Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt signals/slot QThread > GUI with lambdas functions

Qt signals/slot QThread > GUI with lambdas functions

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 708 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OPit
    wrote on last edited by OPit
    #1

    Hello,
    I use Qt6.4 on Windows and I have a mistake from a signal/slot error.

    I have a QThread send a signal to my main GUI to show an error message :

    connect(m_uploaderServer, &PortalUploader::error, [this](const QString & message)
        {
            m_labelError->setText(message);
            m_labelError->show();
        });
    

    But when the signals is emitted, I have this error :

    [09/01/2023-13:46:33.439] QBasicTimer::start: Timers cannot be started from another thread
    [09/01/2023-13:46:33.439] QObject::setParent: Cannot set parent, new parent is in a different thread
    

    I don't have this error if my QLabel is always visible (not use show() function).

    I don't understand this error. If I call directly from my thead the show() function, I understand why it is not correct, but in this case ?? Do I not use correctly signal/slot mechanism ? Somebody knows why ?

    Thanks

    [EDIT] : it seems that the lambda function that makes problem. When I use a member slot function, it's OK. Somebody knows why ?

    [EDIT2] I found the answer. In documentation, it says:

    the lambda will be called in the thread of the event loop of the object used as context).
    

    I keep my post, it can help someone else ...

    Chris KawaC 1 Reply Last reply
    0
    • O OPit

      Hello,
      I use Qt6.4 on Windows and I have a mistake from a signal/slot error.

      I have a QThread send a signal to my main GUI to show an error message :

      connect(m_uploaderServer, &PortalUploader::error, [this](const QString & message)
          {
              m_labelError->setText(message);
              m_labelError->show();
          });
      

      But when the signals is emitted, I have this error :

      [09/01/2023-13:46:33.439] QBasicTimer::start: Timers cannot be started from another thread
      [09/01/2023-13:46:33.439] QObject::setParent: Cannot set parent, new parent is in a different thread
      

      I don't have this error if my QLabel is always visible (not use show() function).

      I don't understand this error. If I call directly from my thead the show() function, I understand why it is not correct, but in this case ?? Do I not use correctly signal/slot mechanism ? Somebody knows why ?

      Thanks

      [EDIT] : it seems that the lambda function that makes problem. When I use a member slot function, it's OK. Somebody knows why ?

      [EDIT2] I found the answer. In documentation, it says:

      the lambda will be called in the thread of the event loop of the object used as context).
      

      I keep my post, it can help someone else ...

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @OPit said:

      the lambda will be called in the thread of the event loop of the object used as context

      A simple fix is to add that context i.e.

      connect(m_uploaderServer, &PortalUploader::error, m_labelError, [this](...
                                                        ^
                                                        here
      
      1 Reply Last reply
      1
      • O Offline
        O Offline
        OPit
        wrote on last edited by
        #3

        Oh great, thanks for your answer !

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved