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. Problem with signal/slot from class

Problem with signal/slot from class

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 618 Views 2 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.
  • nageshN Offline
    nageshN Offline
    nagesh
    wrote on last edited by
    #2

    @ademmler said in Problem with signal/slot from class:

    Qt::BlockingQueuedConnection

    remove the last argument and check it, let it be decided based on the signalling and receiver object context.

    Qt::BlockingQueuedConnection in this type of connection the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock.
    
    ademmlerA 1 Reply Last reply
    2
    • nageshN nagesh

      @ademmler said in Problem with signal/slot from class:

      Qt::BlockingQueuedConnection

      remove the last argument and check it, let it be decided based on the signalling and receiver object context.

      Qt::BlockingQueuedConnection in this type of connection the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock.
      
      ademmlerA Offline
      ademmlerA Offline
      ademmler
      wrote on last edited by
      #3

      @nagesh thx for oyur response. the problem still exists .

      connect( mColorLib, &ColorLib::signalTellUser, this, &SpectraProof::slotTellUser);

      What is the best way to debug slots/signals?
      The connect seems to be valid, because I do not get any complains while application launch.

      1 Reply Last reply
      0
      • ademmlerA ademmler

        Hi there:
        I have issues getting a signal/slot working from a class. Does this class need to be a thread to accept signal/slots?

        In the main app I connect like this:

        mColorLib = new ColorLib(this);
            connect( mColorLib, &ColorLib::signalTellUser, this, &SpectraProof::slotTellUser, Qt::BlockingQueuedConnection );
        

        What I send from class:

        emit signalTellUser(tr("Warning:"), tr("File format not supported yet."));
        

        My class header:

        class ColorLib : public QObject
        {
            Q_OBJECT
        
        public:
            explicit ColorLib(QObject *parent = 0);
        
        
        signals:
            void signalTellUser(QString title, QString message);
        
        public:
            void open(QDir colorLibSubFolder);
        
        };
        #endif // COLORLIB_H
        
        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @ademmler said in Problem with signal/slot from class:

        What I send from class:

        From where and when?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        ademmlerA 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @ademmler said in Problem with signal/slot from class:

          What I send from class:

          From where and when?

          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by
          #5

          @Christian-Ehrlicher the class emits the signal and the slot is in the main app ...
          I do the same with another class - same code lines and there it works ...
          Hence I do not recall find any difference.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @ademmler said in Problem with signal/slot from class:

            the class emits the signal and the slot is in the main app ...

            Which functions triggers the signal? Are you sure the correct instance is used? Simply add some debug output or use a debugger to see what instance you're using where.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            ademmlerA 1 Reply Last reply
            3
            • Christian EhrlicherC Christian Ehrlicher

              @ademmler said in Problem with signal/slot from class:

              the class emits the signal and the slot is in the main app ...

              Which functions triggers the signal? Are you sure the correct instance is used? Simply add some debug output or use a debugger to see what instance you're using where.

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by
              #7

              @Christian-Ehrlicher I have the debug output at the correct spot.
              Right above the emit signal statement. Also no warnings about a "wrong" connect object ...
              It is really wired. My only idea ist that this class over takes an Object while the other (where it is working) over takes a Thread. Does it need to be a Thread?

              Not working:

              ColorLib::ColorLib(QObject *parent)
              : QObject(parent)
              {
              }
              

              Working:

              MyMeasure::MyMeasure(QObject *parent):
                  QThread(parent)
              {
              }
              
              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Please provide a minimal, compilable example. Your code snippets don't help. Please show at least where you do the connect and emit the signal to see if you really call the correct object.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                ademmlerA 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  Please provide a minimal, compilable example. Your code snippets don't help. Please show at least where you do the connect and emit the signal to see if you really call the correct object.

                  ademmlerA Offline
                  ademmlerA Offline
                  ademmler
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher thx for this suggestion. I can't upload here in the forum.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @ademmler said in Problem with signal/slot from class:

                    I can't upload here in the forum.

                    When it's minimal I would say it's below 50 lines of code so you can paste them here.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    ademmlerA 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      @ademmler said in Problem with signal/slot from class:

                      I can't upload here in the forum.

                      When it's minimal I would say it's below 50 lines of code so you can paste them here.

                      ademmlerA Offline
                      ademmlerA Offline
                      ademmler
                      wrote on last edited by
                      #11

                      @Christian-Ehrlicher ok - that will take time - and of course in a minimal it is working corecctly. This we have tested already in another thread a year ago.

                      In the same project - slot/signal works if the class is derived with QThread and it does not if it misses QThread. Does this make a difference?

                      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