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 Updated to NodeBB v4.3 + New Features

failed connect

Scheduled Pinned Locked Moved Solved General and Desktop
connect failure
12 Posts 4 Posters 5.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.
  • 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

                      12/12

                      17 Aug 2016, 09:28

                      • Login

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