Results 1 to 2 of 2

Thread: Problem creating a QWidget using threads

  1. #1
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem creating a QWidget using threads

    Hello there!

    We have a QApplication which launch a posix thread which communicates with a server. When some messages arrives is neccesary to display some qt windows. When we try to create the Qt windows from the posix thread the following error appears:

    Xlib: unexpected async reply (sequence 0x79)!

    (the value of the sequence may differs between executions).

    The following conditions are required:
    - The thread must not be a Qt thread.
    - The windows must be created and destroyed (not show/hide).

    Any suggestion would be appreciated.

    Thank you!!

    --

    Source example. This is not a working example: just for understanding concept only. It will not compile.

    file: main.cpp
    --------------

    #include <QCoreApplication>
    #include <QWidget>
    #include "buildIHMITestMgrSubscripter.h"
    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QWidget>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    buildIHMITestMgrSubscripter *Manager; //Thread launching class.
    Manager = new buildIHMITestMgrSubscripter();
    return app.exec();
    }
    EOF ################################################## ##############

    file: buildIHMITestMgrSubscripter.h
    -----------------------------------

    #include <time.h>
    #include <iostream>
    #include "thread.h"
    #include "impl_controlsTest_1.h"

    class buildIHMITestMgrSubscripter
    {
    public:
    buildIHMITestMgrSubscripter();
    static void* getBuildIHMITestNotify( void * pthis );
    private:
    impl_controlsTest_1* formControlTest1;

    thread* oThread;
    };

    EOF ################################################## ##############

    file buildIHMITestMgrSubscripter.cpp
    ------------------------------------

    #include "buildIHMITestMgrSubscripter.h"

    using namespace std;

    buildIHMITestMgrSubscripter::buildIHMITestMgrSubsc ripter()
    {
    oThread = new thread( getBuildIHMITestNotify, 10, 0, 65536, (void*)this );
    formControlTest1 = NULL;
    }

    void* buildIHMITestMgrSubscripter::getBuildIHMITestNotif y( void * pthis )
    {
    buildIHMITestMgrSubscripter *oBuildTestSub = ( buildIHMITestMgrSubscripter* )pthis;
    formControlTest1 = new impl_controlsTest_1(); //This line crashes the application.
    formControlTest1->setGeometry( QRect( 0,0,388,271 ) );
    formControlTest1->show();

    while( true )
    {
    //Here goes the code to listen server messages (not included)...
    }
    }

    EOF ################################################## ##############

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem creating a QWidget using threads

    Hi,

    Take a look at QThread doc. You cannot create (manipulate) any GUI element in another thread than the main thread.
    You will have to emit a signal to the main thread and there you have to create(manipulate) the widgets.
    Òscar Llarch i Galán

Similar Threads

  1. Problem with Parent QWidget and Buttons not working
    By VireX in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2007, 23:24
  2. Threads problem
    By boss_bhat in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2006, 16:41
  3. Problem in creating thread in GUI application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 13:05
  4. Replies: 16
    Last Post: 7th March 2006, 16:57
  5. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 23:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.