A piece of code allows you to learn the Chinese display of QT, and open and save the file.

Source: Internet
Author: User

For example, it is very troublesome to display the Chinese character of QT. You need to use the local encoding method and then obtain the string. Attached file operations, file writing also supports Chinese:

 

# Include <qtwidgets/qapplication> # include <qfiledialog> # include <qtextcodec> # include <qtextstream> int main (INT argc, char * argv []) {qapplication A (argc, argv); qstring STR; STR = Str. fromlocal8bit ("dinner"); qtextcodec * codec = qtextcodec: codecforlocale (); qstring AA = codec-> tounicode ("QT Chinese display"); qt2 W; W. show (); qstring dir = qfiledialog: getexistingdirectory (& W, STR, "C:"); qstring wrfile = qfiledia Log: getsavefilename (& W, AA, DIR); qstringlist open = qfiledialog: getopenfilenames (& W, "open files", "d: \ c_proj "); qfile file (wrfile); If (! File. open (qiodevice: writeonly | qiodevice: Text) return 1; qtextstream out (& file); out <"the magic number is: "<49 <" \ n "; out <AA <Endl; For (qstringlist: iterator iter = open. begin (); iter! = Open. End (); ITER ++) {out <* ITER <Endl;} return a.exe C ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.