c++ - How to use GUI while threads doing their jobs in QT? -


as self-learner, trying understand qthread logics in c++ qt. wrote simple thread class has loop inside. when thread inside loop cannot use mainwindow. try open qfiledialog , select files. when press "open" button thread runs , filedialog not closing until thread finish job.

is possible use mainwindow while thread working background?

here simple code try..

void mainwindow::on_pushbutton_clicked() {     qfiledialog *lfiledialog = new qfiledialog(this, "select folder", "/.1/projects/", "*");      qstringlist selectedfilenames = lfiledialog->getopenfilenames(this, "select images", "/home/mg/desktop/", "", 0, 0);      if(!selectedfilenames.isempty())     {         mythread mthread1;         mthread1.name = "thread1";         mthread1.run();         mthread1.wait();     } }   void mythread::run() {     (int var = 0; var < 100000; ++var)     {         qdebug() << this->name << var;     } } 

you shouldn't wait() on thread in click handler! also, don't call thread's run yourself, start thread. starting thread call run().


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -