Qt GUI設計 介面語言動態切換(2)

2021-06-08 04:06:07 字數 2009 閱讀 8289

接著上次做的語言切換

上次實現了語言動態切換,但是並不能儲存,就是下次開啟時語言又會恢復成原來的

這次程式中加入語言配置檔案,每次語言修改會記錄儲存,下次開啟時語言就是上次儲存的。

**如下

#include

"dialog.h"

#include

"ui_dialog.h"

#include

#include

#include

#include

dialog

::dialog

(qwidget

*parent

):

qdialog

(parent

),

ui(

newui

::dialog

)

dialog

::~dialog

()

void

dialog

::switchlanguage(

intflag

)

}

elseif(

flag==1

)

else

}

}

}
void

dialog

::to_chinese(

void

)

}

}
void

dialog

::to_english(

void

)

}

}
#include

#include

"dialog.h"

#include

#include

#include

#include

#include

int

main(

intargc

,char

*argv

)

qtranslator

translator(0

);

boolb=

false

;

b=

translator

.load(

language

);

if(

b==false

)

qdebug(

"load

err!"

);

else

qdebug(

"load

ok");

a.installtranslator(&

translator

);

dialog

w;

w.show();

return

a.exec();

}

C winform介面的語言切換

if file.exists xmlpath 不存在xml檔案,建立檔案並寫入根節點 xmldocument xmldoc new xmldocument xmldoc.load xmlpath xmlnode xmlnode xmldoc.getelementbyid form.name if x...

C winform介面的語言切換

if file.exists xmlpath 不存在xml檔案,建立檔案並寫入根節點 xmldocument xmldoc new xmldocument xmldoc.load xmlpath xmlnode xmlnode xmldoc.getelementbyid form.name if x...

QT的動態語言切換

1.在.pro檔案裡新增的內容如下 2.新增好以後,在工具 外部 qt語言家 更新語言 啟動外部工具 c qt 4.8.6 bin lupdate.exe c qt test qtwidget qtwidget.pro updating zh cn.ts found 7 source text s ...