c++ - what is the effective scope of setCodecfForTr() -


i'm have following in main.cpp file,

int main(int argc, char *argv[]) {     qapplication a(argc, argv);       qtextcodec::setcodecforcstring(qtextcodec::codecforname("utf-8"));      mainwindow w;     w.show();      return a.exec(); } 

and following mainwindow.cpp

mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);          result = new qlabel("check result here:",this);      result->setgeometry(qrect(qpoint(180,30),qsize(161,161)));      qstring m("宁愿看见两个恶魔在拔河,也不愿看见一只天使在跳舞。");      result->settext(m);  }  mainwindow::~mainwindow() {     delete ui; } 

the chinese character on qlabel can not displayed normally.

if modify them follows, character can displayed normally.

int main(int argc, char *argv[]) {     qapplication a(argc, argv);      mainwindow w;     w.show();      return a.exec(); } 

the following mainwindow.cpp

mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);         qtextcodec::setcodecforcstring(qtextcodec::codecforname("utf-8"));      result = new qlabel("check result here:",this);      result->setgeometry(qrect(qpoint(180,30),qsize(161,161)));      qstring m("宁愿看见两个恶魔在拔河,也不愿看见一只天使在跳舞。");      result->settext(m);  }  mainwindow::~mainwindow() {     delete ui; } 

i think problem of scope of function 'setcodeforcstring()`, can explain that?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -