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

Problem in using the Connect

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.2k 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.
  • MrErfanM Offline
    MrErfanM Offline
    MrErfan
    wrote on 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
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      MrErfanM 1 Reply Last reply
      0
      • jsulmJ jsulm

        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.

        MrErfanM Offline
        MrErfanM Offline
        MrErfan
        wrote on last edited by MrErfan
        #3

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

        jsulmJ 2 Replies Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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
          • MrErfanM MrErfan

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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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
            • MrErfanM MrErfan

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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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

              • Login

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