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. failed connect
Forum Update on Monday, May 27th 2025

failed connect

Scheduled Pinned Locked Moved Solved General and Desktop
connect failure
12 Posts 4 Posters 4.9k Views
  • 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.
  • N Offline
    N Offline
    nischu
    wrote on 16 Aug 2016, 16:40 last edited by
    #1

    Hello there, I'm trying from a tutorial making a small tictactoe game with Qtcreator. That's my first project with Qt.
    When I run the binary, I get these two messages:

    Starting /home/sven/develop/Qt/build-tictactoe-Desktop_Qt_5_6_0_GCC_64bit-Debug/tictactoe...
    QObject::connect: No such signal TicTacToeWidget::currentPlayerChanged(TicTacToeWidget::Player) in ../tictactoe/mainwindow.cpp:17
    QObject::connect:  (sender name:   'gameBoard')
    QObject::connect:  (receiver name: 'MainWindow')
    QObject::connect: No such signal TicTacToeWidget::gameOver(TicTacToeWidget::Player) in ../tictactoe/mainwindow.cpp:20
    QObject::connect:  (sender name:   'gameBoard')
    QObject::connect:  (receiver name: 'MainWindow')
    

    But i have both functions in the 'signals' part in the class declaration of TicTacToeWidget.
    What else could be caused this errors?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 16 Aug 2016, 16:49 last edited by
      #2

      hi and welcome
      One common error is that moc.exe was not run so it dont know it has the signals.
      Or forgetting the Q_OBJECT macro in the class .h

      So check if u have Q_OBJECT
      do clean all
      run qmake
      rebuild

      if it still says it, please post some code :)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nischu
        wrote on 16 Aug 2016, 18:29 last edited by
        #3

        Q_OBJECT is set, and the build process was without warnings.

        The perfidious is, that i have all source files belonging to the tutorial so i was being able to compare these to my own try. But although I compared every piece of code, I didn't found a semantic distinction.
        Only the *.ui files I couldn't check, that would too wearisome for me.

        Here the code for the connect statements:

        MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent), ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            connect( ui->actionNewGame, SIGNAL(triggered()),
                     this, SLOT(startNewGame()));
        
            connect( ui->actionQuit, SIGNAL(triggered()),
                     qApp, SLOT(quit()));
        
            connect( ui->gameBoard, SIGNAL(currentPlayerChanged(TicTacToeWidget::Player))
                     , this, SLOT(updateNameLabels()));
        
            connect( ui->gameBoard, SIGNAL(gameOver(TicTacToeWidget::Player))
                     , this, SLOT(handleGameOver(TicTacToeWidget::Player)));
        }
        

        The first two connections will created fine.

        I suppose i made a mistake within Designer Mode, but i have no clue where.
        Could it be that I made a mistake at naming the sender's source? But i don't see such thing, in the Designer Mode's Object Inspector.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 Aug 2016, 18:35 last edited by
          #4

          @nischu said:
          hi the UI is just translated into code. ( the setUI function)
          so i doubt it has anything to do with it.

          also since you use directly connect, you are in control.

          one thing i do wonder

          connect( ui->gameBoard, SIGNAL(currentPlayerChanged(TicTacToeWidget::Player))
          , this, SLOT(updateNameLabels()));

          should that not be
          connect( ui->gameBoard, SIGNAL(currentPlayerChanged(TicTacToeWidget::Player))
          , this, SLOT(updateNameLabels(TicTacToeWidget::Player)));

          anyway, you can check what connect returns to see if it fails

          qDebug() << "con1:" << connect(xxx

          it says TRUE when it accepts the connect.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nischu
            wrote on 16 Aug 2016, 19:01 last edited by
            #5

            @mrjj said:
            should that not be
            connect( ui->gameBoard, SIGNAL(currentPlayerChanged(TicTacToeWidget::Player))
            , this, SLOT(updateNameLabels(TicTacToeWidget::Player)));

            No, it's ok. Here the handling:

            void MainWindow::updateNameLabels()
            {
                QFont f = ui->player1->font();
                f.setBold( ui->gameBoard->currentPlayer() == TicTacToeWidget::Player1);
                ui->player1->setFont(f);
                f.setBold( ui->gameBoard->currentPlayer() == TicTacToeWidget::Player2);
                ui->player2->setFont(f);
            }
            

            Thanks for your hint with QDebug. But that says no news: con1,con2 == true, con3,con4 == false

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 16 Aug 2016, 19:02 last edited by mrjj
              #6

              Hi if you can zip the whole project, i could have a look?
              or link to the tut.
              or show the .h and .cpp where signals/slots are defined

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nischu
                wrote on 16 Aug 2016, 22:27 last edited by
                #7

                mrjj, Thanks for taking your time looking over my source code.
                [Here are my own files]

                [And here the files published by my book] This compiles and runs without errors.

                J M 2 Replies Last reply 17 Aug 2016, 04:12
                0
                • N nischu
                  16 Aug 2016, 22:27

                  mrjj, Thanks for taking your time looking over my source code.
                  [Here are my own files]

                  [And here the files published by my book] This compiles and runs without errors.

                  J Offline
                  J Offline
                  jerome_isAviable
                  wrote on 17 Aug 2016, 04:12 last edited by
                  #8

                  Hi @nischu,
                  when you connect signal and slot the sign has to be exactly the same.
                  If you have a signal signed: currentPlayerChanged(TicTacToeWidget::Player)
                  you need to link with a slot signed: compatibleSlotToBeLinked(TicTacToeWidget::Player)

                  if not, the link not occur as specified in the doc (just before "Advanced Signals and Slots Usage" not far from the end of the article doc.

                  http://doc.qt.io/qt-5/signalsandslots.html

                  1 Reply Last reply
                  2
                  • N nischu
                    16 Aug 2016, 22:27

                    mrjj, Thanks for taking your time looking over my source code.
                    [Here are my own files]

                    [And here the files published by my book] This compiles and runs without errors.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 17 Aug 2016, 06:50 last edited by
                    #9

                    @nischu

                    hi as @jerome_isAviable says

                    it was the name space/scope naming that confused it.
                    "player" vs "TicTacToeWidget::player"

                    void currentPlayerChanged( Player);
                    works if
                    void currentPlayerChanged( TicTacToeWidget::Player );

                    here is fixed and running sample
                    https://www.dropbox.com/s/jvsoulsvmh3292g/tictactoe.zip?dl=0

                    1 Reply Last reply
                    3
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 17 Aug 2016, 07:10 last edited by
                      #10

                      Despite almost all the documentation still using SIGNAL() and SLOT(), you should really switch to the Qt5 syntax https://wiki.qt.io/New_Signal_Slot_Syntax it catches these problems at compile time and makes it easier to solve them

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      M 1 Reply Last reply 17 Aug 2016, 07:21
                      2
                      • V VRonin
                        17 Aug 2016, 07:10

                        Despite almost all the documentation still using SIGNAL() and SLOT(), you should really switch to the Qt5 syntax https://wiki.qt.io/New_Signal_Slot_Syntax it catches these problems at compile time and makes it easier to solve them

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 17 Aug 2016, 07:21 last edited by mrjj
                        #11

                        @VRonin
                        I complete agree that the new syntax has much better checks etc
                        but sadly its very unfriendly to
                        beginners when overloaded signals are used.

                        connect(spinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), slider, &QSlider::setValue);
                        vs
                        connect(spinbox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));

                        Its sad that compile time check has such a high price in syntax complexity and
                        pretty ugly to look at :) ( IMO)

                        update:
                        just seen that Qt 5.7 has qOverload
                        so my point is not so valid :)

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          nischu
                          wrote on 17 Aug 2016, 09:28 last edited by
                          #12

                          Thank you all for helping detect ths error. I will take a close look at the related docs.
                          Regards, Nico

                          1 Reply Last reply
                          1

                          5/12

                          16 Aug 2016, 19:01

                          • Login

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