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. Problem in using the Connect
Forum Update on Monday, May 27th 2025

Problem in using the Connect

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.1k 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.
  • M Offline
    M Offline
    MrErfan
    wrote on 26 Jan 2016, 07:38 last edited by MrErfan
    #1

    Hi
    The problem in using the Connect function in the class after the call, the error:
    QObject :: connect: Incompatible sender / receiver arguments
    MyClass :: finished () -> MyClass :: login (QString, QString)
    My Code :

    //Qml Call run Function    
    MyButton
        {
            width: 250
            height: 45
            x: rect.width / 2 - 33
            y: 200
    
            onClicked: {
                //MyClass.login(txtUserName.text,txtPass.text)
                MyClass.run2()
            }
        }
    
    //MyClass.h
    #ifndef MYCLASS_H
    #define MYCLASS_H
    
    #include <QObject>
    #include <QQuickItem>
    #include <QtSql>
    #include <QThread>
    
    class MyClass : public QObject
    {
        Q_OBJECT
    
    public :
        MyClass();
        ~MyClass();
    public slots :
        void run2();
        void login(QString usr,QString psw);
        void connecttodb();
    signals :
        void started();
        void finished();
    
    };
    
    #endif // MYCLASS_H
    
    //MyClass.cpp
    #include "myclass.h"
    #include <qdebug.h>
    #include <QtSql>
    #include <QTimer>
    
    MyClass::MyClass()
    {
    
    }
    
    MyClass::~MyClass()
    {
    
    }
    
    void MyClass::run2()
    {
        MyClass *w = new MyClass();
        connect(w,SIGNAL(finished()),w,SLOT(login(QString,QString)));
    
    }
    
    void MyClass::login(QString usr,QString psw)
    {
    
    ....
    
        emit finished();
    
    
    }
    }
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Jan 2016, 07:40 last edited by
      #2

      The error already explains what the problem is: connect(w,SIGNAL(finished()),w,SLOT(login(QString,QString)));
      your slot expects to get two parameters, but the signal you're trying to connect does not have any parameters. So, the signal cannot pass parameters the slot expects.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 26 Jan 2016, 07:49
      0
      • J jsulm
        26 Jan 2016, 07:40

        The error already explains what the problem is: connect(w,SIGNAL(finished()),w,SLOT(login(QString,QString)));
        your slot expects to get two parameters, but the signal you're trying to connect does not have any parameters. So, the signal cannot pass parameters the slot expects.

        M Offline
        M Offline
        MrErfan
        wrote on 26 Jan 2016, 07:49 last edited by MrErfan
        #3

        @jsulm
        Thanks very much for guidance, I run function connect() with what to do?

        J 2 Replies Last reply 26 Jan 2016, 07:53
        0
        • J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 26 Jan 2016, 07:50 last edited by
          #4

          Somehow your code is really weird: in MyClass::run2 you create a new instance of the same class, then in login() slot you emit the signal which you want to connect to login() slot! Even if you would be able to connect finished() to login() you would get an infinite loop: call login() -> emit finished() -> login() is called -> emit finished() -> login() is called -> ...
          What do you want to do?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M MrErfan
            26 Jan 2016, 07:49

            @jsulm
            Thanks very much for guidance, I run function connect() with what to do?

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 26 Jan 2016, 07:53 last edited by
            #5

            @MrErfan I don't understand your question.
            You cannot connect a signal without parameter to a slot with parameter.
            Did you read http://doc.qt.io/qt-5.5/signalsandslots.html ?
            Either remove parameter from login() slot or add same parameter to finished() signal.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M MrErfan
              26 Jan 2016, 07:49

              @jsulm
              Thanks very much for guidance, I run function connect() with what to do?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 26 Jan 2016, 08:01 last edited by
              #6

              @MrErfan
              I don't know what you want to do when login() is finished, but do not connect finished() to login()!

              MyClass::MyClass()
              {
                  connect(this,SIGNAL(finished()),this,SLOT(onFinished()));
              }
              
              MyClass::~MyClass()
              {
              }
              
              void MyClass::run2()
              {
                  login("...", "...");
              }
              
              void MyClass::login(QString usr,QString psw)
              {
              ....
                  emit finished();
              }
              
              void MyClass::onFinished()
              {
                  // No idea what you want to do here
              }
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              1/6

              26 Jan 2016, 07:38

              • Login

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