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. No such slot Window::signUp(username,password,passwordRepeat)

No such slot Window::signUp(username,password,passwordRepeat)

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 505 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.
  • P Offline
    P Offline
    progloveprog
    wrote on last edited by progloveprog
    #1

    Hi,
    I don't know why but my qt shows
    No such slot Window::signUp(username,password,passwordRepeat) error
    this is my code
    window.cpp

    #include <QApplication>
    #include <QPushButton>
    #include <QLineEdit>
    #include <QMessageBox>
    #include <window.h>
    
    
    void Window::signUp(QString username,QString password,QString passwordRepeat){
        QMessageBox msgBox;
        msgBox.setText("Username :"+username+" password :"+password +" password repeat :"+passwordRepeat);
        msgBox.exec();
        msgBox.show();
    }
    Window::Window(QWidget *parent) :
        QWidget(parent)
    {
        setFixedSize(400,400);
        usernameLine = new QLineEdit(this);
        usernameLine->setGeometry(100,50,200,30);
        usernameLine->setPlaceholderText("username");
        QString username = usernameLine->text();
    
        passwordLine = new QLineEdit(this);
        passwordLine->setPlaceholderText("password");
        passwordLine->setGeometry(100,90,200,30);
        QString password = passwordLine->text();
    
        passwordRepeatLine = new QLineEdit(this);
        passwordRepeatLine->setPlaceholderText("password repeat");
        passwordRepeatLine->setGeometry(100,130,200,30);
        QString passwordRepeat = passwordRepeatLine->text();
    
        button = new QPushButton("Submit",this);
        button->setGeometry(150,180,100,30);
        QObject::connect(button, SIGNAL(clicked()),this, SLOT(signUp(username,password,passwordRepeat)));
    
    }
    

    window.h

    #ifndef MAIN_H
    #define MAIN_H
    
    
    #include <QWidget>
    class QPushButton;
    class QLineEdit;
    class Window : public QWidget
    {
     Q_OBJECT
     public:
      explicit Window(QWidget *parent = 0);
    
     /*signals:
     public slots:*/
     private:
        QPushButton *button;
        QLineEdit *usernameLine;
        QLineEdit *passwordLine;
        QLineEdit *passwordRepeatLine;
     public slots:
        void signUp(QString,QString,QString);
    };
    
    
    #endif 
    
    

    Why am I getting no such slot when I already declared slot in header file?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #7

      Just remove the parameters of your slot and retrieve there the values you need.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Because you are passing arguments and not the correct signature.

        You should use the new syntax so you will get compile time error rather than runtime.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Because you are passing arguments and not the correct signature.

          You should use the new syntax so you will get compile time error rather than runtime.

          P Offline
          P Offline
          progloveprog
          wrote on last edited by
          #3

          @SGaist
          Unfortunately I don't think I can use new syntax for this project. Link I got from my professor does not use a new syntax if I guess right. Can't it be done with old syntax?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Sure it can be done, but not the way you do it. You cannot connect a slot that has more parameters than the signal you are connecting from.

            Which version of Qt are you using by the way ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            P 1 Reply Last reply
            0
            • SGaistS SGaist

              Sure it can be done, but not the way you do it. You cannot connect a slot that has more parameters than the signal you are connecting from.

              Which version of Qt are you using by the way ?

              P Offline
              P Offline
              progloveprog
              wrote on last edited by
              #5

              @SGaist I am using qmake version 3.0

              I understand what you mean, so I tried

              QObject::connect(button, SIGNAL(clicked(username,password,passwordRepeat)),this, SLOT(signUp(username,password,passwordRepeat)));
              

              But it shows
              QObject::connect: No such signal QPushButton::clicked(username,password,passwordRepeat)

              I guess I have to create custom clicked signal in header file, isn't it?

              JonBJ 1 Reply Last reply
              0
              • P progloveprog

                @SGaist I am using qmake version 3.0

                I understand what you mean, so I tried

                QObject::connect(button, SIGNAL(clicked(username,password,passwordRepeat)),this, SLOT(signUp(username,password,passwordRepeat)));
                

                But it shows
                QObject::connect: No such signal QPushButton::clicked(username,password,passwordRepeat)

                I guess I have to create custom clicked signal in header file, isn't it?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @progloveprog
                You have to write the types of the parameters where you have written parameter names, in the SIGNAL & SLOT() macros.

                But you also cannot "invent" that an existing signal, like QPushButton::clicked(), passes extra parameters like you have done. It does not pass those.

                I guess I have to create custom clicked signal in header file, isn't it?

                If you do it that way then yes you would need to do that. There are different ways, but we don't know what "your professor" is wanting you to do here :)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Just remove the parameters of your slot and retrieve there the values you need.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  P 1 Reply Last reply
                  2
                  • SGaistS SGaist

                    Just remove the parameters of your slot and retrieve there the values you need.

                    P Offline
                    P Offline
                    progloveprog
                    wrote on last edited by
                    #8

                    @SGaist
                    Thank you
                    That was the right way to go hahaha
                    I didn't think it would be possible to read text of UI from outside of Window::Window

                    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