Results 1 to 4 of 4

Thread: Non-GUI thread

  1. #1
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Non-GUI thread

    Hello; I'm writing a Gui that use lib callbacks where I have no control of them. I have created a class that inherits from QWidget and

    library listener so when something happens, this function is called by the library:
    Qt Code:
    1. class MyClass : public QWidget, public LibraryListener
    2. {
    3. MyClass(QWidget *parent = 0) : QWidget(parent)
    4. {
    5. Library::getIstance()->addListener(this); // add the listener
    6. }
    7. }
    8.  
    9. void MyClass::on(Listener::listener, Object *o)
    10. {
    11. emit signal(o);
    12. }
    To copy to clipboard, switch view to plain text mode 

    Library lives in own thread and it usually starts others. I know Qt complains if the sender's and receiver's thread ae different. Infact

    application is killed with the following error:
    ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 2aaaac07be40.

    Receiver 'updateButton' (of type 'QPushButton') was created in thread 6a9db0", file kernel/qcoreapplication.cpp, line 274
    It usually works and it usually don't. Why doesn't this problem happen always?

    I think I should create a new class that inherits from QThread and this class through queued signals handles lib thread. Am I wrong?

    Thank your your answer

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Non-GUI thread

    You have to provide more code or better yet present a minimal compilable example reproducing the problem.

  3. #3
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Non-GUI thread

    Thank you so much for your quick answer
    Sorry wysota, I think it crashed because I did this:
    Qt Code:
    1. emit slot(o);
    To copy to clipboard, switch view to plain text mode 
    I used a slot instead of signal!

    Last question: do u think that is the right approach emitting signal when client callback is called or is it better to handle it with QThread?

    Thank you sir
    Last edited by foxyproxy; 11th April 2008 at 12:51.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Non-GUI thread

    You can emit signals wherever you see fit.

Similar Threads

  1. Replies: 5
    Last Post: 17th January 2008, 21:49
  2. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44

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.