Implementation of GUI development on QT

Source: Internet
Author: User
Tags dsn

1. Directory

    • Using ODBC Excel files (xls) from input data
    • Gui entry-level design
    • Qfile usage in QT
    • Solve Chinese garbled characters in QT

2. Use ODBC Excel files (xls) from input data

    • Main website reference: http://blog.csdn.net/u010780613/article/details/51151448
    • Main Code:
      Qstring STR; STR = qstring: fromlocal8bit ("select an Excel file"); qstring filepath = qfiledialog: getopenfilename (this, STR ,"", TR ("Exel file (*. (xls) "); // read from the Excel file path // load the database driver qsqldatabase DB = qsqldatabase: adddatabase (" qodbc "," excelexport "); // DSN set qstring DSN = "driver = {Microsoft Excel Driver (*. XLS)}; "" DSN = ''; firstrowhasnames = 1; readonly = false; create_db ="; dB. setdatabasename (DSN); // database query qsqlquery query (db); qdebug () <qstring: fromlocal8bit (""); qstring tablename = "sheet1 $ "; // Sheet Name, $ is a required qstring SQL = "select * from [" + tablename + "]" Explain query.exe C (SQL); // read data while (query. next () {qstring id = query. value (0 ). tostring (); qstring name = query. value (1 ). tostring ();}
      DB. Close ();

       

3. Entry-level GUI Design

    • Create a QT Window project
    • Open the UI and design the UI
    • Click F4. Signal and slot concept explanation: http://www.cnblogs.com/tgycoder/p/5274681.html
    • Define and implement the slot function in the. h file and. cpp file on the interface (the slot function must correspond to the signal)
      private slots:    void input();    void output();    void quit();    

4. Usage of qfile in QT

    • Main reference: http://blog.csdn.net/xgbing/article/details/7772953
    • Qstring filename = qfiledialog: getsavefilename (this, STR, "savefile.txt", TR ("*. TXT "); // select the path qfile F (filename); STR = qstring: fromlocal8bit (" export file... "); qtextstream txtoutput (& F); txtoutput <STR <" \ n ";

5. Solve Chinese garbled characters in QT

    • Source: http://blog.csdn.net/kunlong0909/article/details/8983562
    • Qstring Chinese garbled to solve the statement
      Qstring STR = qstring: fromlocal8bit ("export file ...");
    • When cout is encountered in QT programming, the Chinese output is garbled. Solution: Change the text encoding of the project to gb2312, and solve the problem of creating a new project.

Implementation of GUI development on QT

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.