Results 1 to 4 of 4

Thread: GUI and non-GUI thread problem

  1. #1
    Join Date
    Aug 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default GUI and non-GUI thread problem

    I have GUI thread and non-gui thread, that monitors status of the some device.

    When the device state changed non-gui thread executes the function that changes some items in GUI, but I get errors and incorrect work of GUI.

    QPixmap: It is not safe to use pixmaps outside the GUI thread
    QPixmap: It is not safe to use pixmaps outside the GUI thread
    QPixmap: It is not safe to use pixmaps outside the GUI thread
    QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
    QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread


    What can I do to make this work properly?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GUI and non-GUI thread problem

    You must not use any gui classes etc from the non-gui thread (i.e. not from any threads you created).

    Use (queued) signals or custom events to "signal" the gui thread about state changes in your thread and have the gui thread update the gui accordingly.

    (Hint: search this forum for "thread" and "gui". Should give many useful threads. E.g. today's "how to use prograssbar in a thread".)

    HTH

  3. #3
    Join Date
    Aug 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GUI and non-GUI thread problem

    I've try to use signals, but got error:

    in class:
    signals:
    void canceled();

    in constructor
    connect(this, SIGNAL(canceled()), kiosk, SLOT(cancel()));

    in run()
    emit canceled();

    and got
    undefined reference to `PrinterStatusThread::canceled()'

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GUI and non-GUI thread problem

    Probably you forgot to add the Q_OBJECT line to your class decl or to add the header to your .pro files HEADERS section (and thus moc did not get run on your class).

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.