Results 1 to 8 of 8

Thread: Problem with QLabel and setText

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QLabel and setText

    This is a QT application. I've used winapi because it's similar to me. I've never used QThread, but I will try.

    Thanks

  2. #2
    Join Date
    Oct 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QLabel and setText

    "wysota: You can't access QObject subclasses from within a worker thread."

    Sometimes I can:

    lblCommand->adjustSize(); //pass
    lblCommand->childAt(20,20); //pass
    lblCommand->setVisible(true); //crash

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with QLabel and setText

    In other words, you MUST NOT touch GUI from a worker thread.

    QObject Reentrancy:
    Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread.

    In practice, the impossibility of using GUI classes in other threads than the main thread can easily be worked around by putting time-consuming operations in a separate worker thread and displaying the results on screen in the main thread when the worker thread is finished. This is the approach used for implementing the Mandelbrot and the Blocking Fortune Client example.
    J-P Nurmi

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

    Default Re: Problem with QLabel and setText

    Quote Originally Posted by jambrek View Post
    Sometimes I can:

    lblCommand->adjustSize(); //pass
    lblCommand->childAt(20,20); //pass
    lblCommand->setVisible(true); //crash
    Try running those in a loop and do something else with the GUI in between (like move the window with your mouse). While childAt() might suceed as it doesn't touch much of the structures, adjustSize() is bound to fail eventually. setVisible() is an obvious candidate for an immediate crash though

  5. #5
    Join Date
    Oct 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QLabel and setText

    Problem is solved by using signal and slots. I've created signals which connected to setText slots for each label. It works.

    Thanks a lot.

Similar Threads

  1. Replies: 1
    Last Post: 26th November 2006, 09:32

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
  •  
Qt is a trademark of The Qt Company.