Tips and tricks

How to create a QT GUI Application that reads a text file and outputs in a Text Box
  1. create new QT Project, choose QT C++ Project > Qt Gui Application, click Next
  2. name your application as you wish, click Next
  3. leave everything as it is, click Next
  4. click Finish
  5. click on the Design Tab, drag a Text Edit box
  6. include the following headers
    #include "ui_mainwindow.h"
    #include <QFile>
    #include <QTextStream>
    #include <QString>
    #define IO_ReadOnly QIODevice::ReadOnly
  7. write this function before the main function
    void MainWindow::populate(){}
    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    MainWindow w;;

    return a.exec();

  8. inside MainWindow.h add
    explicit MainWindow(QWidget *parent = 0);

    Ui::MainWindow *ui;
    public slots:
    void populate();


  9. open main.cpp – inside main() function add w.populate();
  10. inside MainWindow::populate() write  ui->textEdit->append(“test”);
  11. if it works, we can go forward, if not, review the steps
  12. write this inside populate functionQFile file("c:/in.txt"); // Create a file handle for the file named
    QString line;

    if (! // Open the file
    // handle error

    QTextStream stream( &file ); // Set the stream to read from myFile


    line = stream.readLine(); // this reads a line (QString) from the file

  13. write your text file in.txt in C:
  14. all done, download the source if you need to –
{"type":"main_options","images_arr":"'#ffffff'","enable_ajax":"off","soundcloud_apikey":"","bg_isparallax":"off","bg_slideshow_time":"0","bg_transition":"slidedown","site_url":"https:\/\/","theme_url":"https:\/\/\/wp-content\/themes\/qucreative\/","blur_ammount":"26","width_column":"50","width_section_bg":"","width_gap":"30","border_width":"0","border_color":"#ffffff","translate_cancel_comment":"Cancel reply","translate_leave_a_comment":"Leave a comment","translate_leave_a_comment_to":"Leave a comment to","is_customize_preview":"off","width_blur_margin":"30","gallery_w_thumbs_autoplay_videos":"off","enable_native_scrollbar":"on","content_enviroment_opacity":"30","menu_enviroment_opacity":"70"}