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. A simple connection error
Qt 6.11 is out! See what's new in the release blog

A simple connection error

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 895 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.
  • Q qcoderpro

    @Pablo-J-Rogina

    Don't understand this either!
    Here both QSplineBox and QSlider have one valueChanged/setValue respectively with one parameter of type int. Everything looks matched. Can't find the clue for the problem yet.

    B Offline
    B Offline
    Bonnie
    wrote on last edited by
    #4

    @qcoderpro
    Actually QSpinBox has two valueChanged signals:

    void valueChanged(int i)
    void valueChanged(const QString &text)

    Q 1 Reply Last reply
    0
    • B Bonnie

      @qcoderpro
      Actually QSpinBox has two valueChanged signals:

      void valueChanged(int i)
      void valueChanged(const QString &text)

      Q Offline
      Q Offline
      qcoderpro
      wrote on last edited by
      #5

      @Bonnie

      Where is the QString based one? I only found the int based: https://doc.qt.io/qt-5/qspinbox-members.html

      B 1 Reply Last reply
      0
      • Q qcoderpro

        @Bonnie

        Where is the QString based one? I only found the int based: https://doc.qt.io/qt-5/qspinbox-members.html

        B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #6

        @qcoderpro
        It is in the Obsolete Members :)

        Q 1 Reply Last reply
        0
        • B Bonnie

          @qcoderpro
          It is in the Obsolete Members :)

          Q Offline
          Q Offline
          qcoderpro
          wrote on last edited by
          #7

          @Bonnie
          Ow, found, thanks, solved.

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qcoderpro
            wrote on last edited by qcoderpro
            #8

            Another connection problem:

            "dialogTest.h":

            #ifndef DIALOGTEST_H
            #define DIALOGTEST_H
            
            #include <QDialog>
            
            class QPushButton;
            class QLineEdit;
            class dialogTest : public QDialog
            {
                Q_OBJECT
            
            public:
                dialogTest(QWidget *parent = nullptr);
                ~dialogTest();
            
            private:
                QPushButton* button;
                QLineEdit* lineEdit;
            };
            #endif // DIALOGTEST_H
            

            "dialogTest.cpp":

            #include "dialogtest.h"
            #include <QPushButton>
            #include <QLineEdit>
            #include <QHBoxLayout>
            #include <QVBoxLayout>
            
            dialogTest::dialogTest(QWidget *parent)
                : QDialog(parent)
            {
                button = new QPushButton(tr("Close"));
                lineEdit = new QLineEdit;
            
                QHBoxLayout* hLayout = new QHBoxLayout;
                hLayout->addWidget(lineEdit);
                hLayout->addWidget(button);
            
                setLayout(hLayout);
            
               connect(button, &QPushButton::clicked, &QDialog, &QDialog::close);
            }
            
            dialogTest::~dialogTest()
            {
                delete button;
                delete lineEdit;
            }
            

            I get this error: error: expected primary-expression before ',' token
            connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close)

            Even when I use this instead:

            connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close);
            

            I get the same error: error: expected primary-expression before ',' token
            connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close);

            B 1 Reply Last reply
            0
            • Q qcoderpro

              Another connection problem:

              "dialogTest.h":

              #ifndef DIALOGTEST_H
              #define DIALOGTEST_H
              
              #include <QDialog>
              
              class QPushButton;
              class QLineEdit;
              class dialogTest : public QDialog
              {
                  Q_OBJECT
              
              public:
                  dialogTest(QWidget *parent = nullptr);
                  ~dialogTest();
              
              private:
                  QPushButton* button;
                  QLineEdit* lineEdit;
              };
              #endif // DIALOGTEST_H
              

              "dialogTest.cpp":

              #include "dialogtest.h"
              #include <QPushButton>
              #include <QLineEdit>
              #include <QHBoxLayout>
              #include <QVBoxLayout>
              
              dialogTest::dialogTest(QWidget *parent)
                  : QDialog(parent)
              {
                  button = new QPushButton(tr("Close"));
                  lineEdit = new QLineEdit;
              
                  QHBoxLayout* hLayout = new QHBoxLayout;
                  hLayout->addWidget(lineEdit);
                  hLayout->addWidget(button);
              
                  setLayout(hLayout);
              
                 connect(button, &QPushButton::clicked, &QDialog, &QDialog::close);
              }
              
              dialogTest::~dialogTest()
              {
                  delete button;
                  delete lineEdit;
              }
              

              I get this error: error: expected primary-expression before ',' token
              connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close)

              Even when I use this instead:

              connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close);
              

              I get the same error: error: expected primary-expression before ',' token
              connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close);

              B Offline
              B Offline
              Bonnie
              wrote on last edited by
              #9

              @qcoderpro
              The third parameter should be a pointer.
              So "& + ClassName" is not a valid expression.
              You should use "this".

              Q 1 Reply Last reply
              0
              • B Bonnie

                @qcoderpro
                The third parameter should be a pointer.
                So "& + ClassName" is not a valid expression.
                You should use "this".

                Q Offline
                Q Offline
                qcoderpro
                wrote on last edited by
                #10

                @Bonnie

                So an address is not accepted and should it exactly be a pointer!? Why?

                And that this you used is actually a pointer to the object we've created in main.cpp, right?

                B 1 Reply Last reply
                0
                • Q qcoderpro

                  @Bonnie

                  So an address is not accepted and should it exactly be a pointer!? Why?

                  And that this you used is actually a pointer to the object we've created in main.cpp, right?

                  B Offline
                  B Offline
                  Bonnie
                  wrote on last edited by Bonnie
                  #11

                  @qcoderpro
                  An address to an QObject object is acceptable. But I don't think "& + ClassName" is an address. It is not a valid expression at all.
                  And I haven't seen your main.cpp with a dialogTest, so I'm not sure.
                  But isn't "this" very basic in C++ class knowledge?

                  Q 1 Reply Last reply
                  1
                  • B Bonnie

                    @qcoderpro
                    An address to an QObject object is acceptable. But I don't think "& + ClassName" is an address. It is not a valid expression at all.
                    And I haven't seen your main.cpp with a dialogTest, so I'm not sure.
                    But isn't "this" very basic in C++ class knowledge?

                    Q Offline
                    Q Offline
                    qcoderpro
                    wrote on last edited by
                    #12

                    @Bonnie

                    Yeah, a pointer varies from an address.

                    This is my main.cpp:

                    #include "dialogtest.h"
                    
                    #include <QApplication>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                        dialogTest w;
                        w.show();
                        return a.exec();
                    }
                    

                    So the "this" you used is the pointer to the object, here "w", as the top-level widget of the project. Is it right?

                    B 1 Reply Last reply
                    0
                    • Q qcoderpro

                      @Bonnie

                      Yeah, a pointer varies from an address.

                      This is my main.cpp:

                      #include "dialogtest.h"
                      
                      #include <QApplication>
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication a(argc, argv);
                          dialogTest w;
                          w.show();
                          return a.exec();
                      }
                      

                      So the "this" you used is the pointer to the object, here "w", as the top-level widget of the project. Is it right?

                      B Offline
                      B Offline
                      Bonnie
                      wrote on last edited by
                      #13

                      @qcoderpro
                      Yeah, using "this" inside dialogTest equals "&w".

                      1 Reply Last reply
                      1

                      • Login

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