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. [Solved] Signal and Slot not connecting for some reason
Forum Updated to NodeBB v4.3 + New Features

[Solved] Signal and Slot not connecting for some reason

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 10.0k 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.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    I like the signal/slot system and use it quite a bit, but I'm completely stumped on this issue. Look at the following code snippet:
    @
    faultLogScreen = new FaultLogWindow();
    myStackedWidget->addWidget(faultLogScreen);
    connect(faultLogScreen, SIGNAL(requestFaultCode(QString*, int)), this, SLOT(deliverFaultCode(QString*, int)));
    connect(updateDisplayTimer, SIGNAL(timeout()), faultLogScreen, SLOT(updateDisplay()));
    connect(faultLogScreen, SIGNAL(activateScreen(int)), this, SLOT(setCurrentScreen(int)));
    @
    Pretty simple and straightforward. I know that the two of the above signal/slot connections work: updateDisplay and setCurrentScreen. For some reason I don't understand, the deliverFaultCode slot is not being connected. I call it like this in the faultLogScreen code:
    @
    emit requestFaultCode(faultStringPtr, sysPos);
    @

    In the function for the deliverFaultCode slot, I have a qDebug() statement that prints out a little message letting me know it gets there, but I never see the message. I know the signals and slots are being defined correctly in the hpp files because everything compiles fine. What am I missing?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Did you check out the output screen?
      It tells you when and what is not correct.
      You can also check the return value for connect for testing if connection failed.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on last edited by
        #3
        1. Do you mean the Application Output tile inside of Qt Creator? That's where I see text from other qDebug() messages.

        2. How and where do I check the return value for connect for testing?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dvdk
          wrote on last edited by
          #4
          1. yes
          2. connect returns true on success (line 3 in your code)

          I also don't think the compiler complains if you have a typo in a signal or slot in the connect line

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Small side note: why are you passing QString* around? QString is very cheap to copy, so you can use it as a simple value.

            To check the connect itself, do something like this:
            @
            bool ok = connect(... the connect stuff);
            Q_ASSERT(ok);
            @

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Endless
              wrote on last edited by
              #6

              Yes, I understand what you're getting at. So, I added [if(connect(....)) qDebug() << "Accepted";] I see that all 3 are being accepted when I look at the application output pane.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                So, that means that the connect is ok, leading to the idea that the emit is not happening.

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  Endless
                  wrote on last edited by
                  #8
                  1. The deliverFaultCode slot returns a string that contains the text for the description of the fault code. Since I didn't think a slot could "return" anything, I used a QString * to be able to look at the value that was set in the deliverFaultCode slot.

                  2. I added the Q_ASSERT(ok) and don't see any warning message in my application output.

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Endless
                    wrote on last edited by
                    #9

                    I call the emit when I populate a QTableWidget. The rest of the table's being populated, so the emit is definitely being called:
                    @
                    faultEntry[index].faultDate = new QTableWidgetItem();
                    faultEntry[index].faultDate->setText(fault[skipLines].dateString);
                    faultEntry[index].faultDate->setTextAlignment(Qt::AlignCenter);
                    logTable->setItem(index, 0, faultEntry[index].faultDate);
                    faultEntry[index].faultTime = new QTableWidgetItem();
                    faultEntry[index].faultTime->setText(fault[skipLines].timeString);
                    faultEntry[index].faultTime->setTextAlignment(Qt::AlignCenter);
                    logTable->setItem(index, 1, faultEntry[index].faultTime);
                    faultEntry[index].faultCode = new QTableWidgetItem();
                    faultEntry[index].faultCode->setText(fault[skipLines].codeString);
                    faultEntry[index].faultCode->setTextAlignment(Qt::AlignCenter);
                    logTable->setItem(index, 2, faultEntry[index].faultCode);
                    sysPos = fault[skipLines].codeString.toInt(&ok, 10);
                    emit requestFaultCode(faultStringPtr, sysPos);
                    faultEntry[index].faultDesc = new QTableWidgetItem();
                    faultEntry[index].faultDesc->setText(faultString);
                    faultEntry[index].faultDesc->setTextAlignment(Qt::AlignCenter);
                    logTable->setItem(index, 3, faultEntry[index].faultDesc);
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      [quote author="Endless" date="1333117644"]1) The deliverFaultCode slot returns a string that contains the text for the description of the fault code. Since I didn't think a slot could "return" anything, I used a QString * to be able to look at the value that was set in the deliverFaultCode slot.
                      [/quote]

                      True, but using a pointer to return a value is dangerous at best. What happens if there are multiple listeners to the signal? And if there are not/can not be, you might as well use a direct method invokation, which would free you from the issue completely.

                      [quote]
                      2) I added the Q_ASSERT(ok) and don't see any warning message in my application output.[/quote]

                      [quote author="Endless" date="1333117793"]I call the emit when I populate a QTableWidget. The rest of the table's being populated, so the emit is definitely being called:[/quote]
                      I guess it is time to fire up your debugger, set a breakpoint at the emit statement, and step into what's going on there...

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        Endless
                        wrote on last edited by
                        #11

                        Where can I read about or see examples of direct method invocation? Another way of passing data would get me away from this signal/slot connection that doesn't work. My debugger freezes up the system not long after my application starts.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          Just a normal method call, I mean by that.

                          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