c++ - How to create a QInputDialog in a new thread? -


basically i'm calling function thread using qtconcurrent.

working expected once create qinputdialog within called function, i'm getting assertion exception telling me have create dialog in main gui thread.

to more specific line:

password = qinputdialog::gettext( , tr( "password" ) , tr( "enter password:" ) , qlineedit::password , selectedpassword , &ok ); 

now question how can call dialog new thread without work.

you can't create widgets outside main thread. can emit signal network thread , create dialog in main thread.

or (pseudo-code):

class notificationmanager : public qobject {   q_object //... public slots:   void showmessage( const qstring& text )   {     if ( qthread::currendthread() != this->thread() )     {       qmetaobject::invoke( this, "showmessage", qt::queuedconnection, q_arg( qstring, text );       // or use qt::blockingqueuedconnection freeze caller thread, until dialog closed       return;     }     qmessagebox::information( nullptr, qstring(), text );   } };  class threadedworker : public qrunnable {   threadedworker( notificationmanager *notifications )     : _notifications( notifications )   {}    void run() override   {     // work;     notifications->showmessage( "show in gui thread" );   }  private:   notificationmanager *_notifications; } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -