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. ERROR QObject::connect: No such slot MainWindow::Inventory(const QString&)

ERROR QObject::connect: No such slot MainWindow::Inventory(const QString&)

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

    I was wrote simple code but I have this error :
    ERROR: QObject::connect: No such slot MainWindow::Inventory(const QString&)

    thread class:

    //.h:
    #ifndef MYTHREAD_H
    #define MYTHREAD_H
    
    #include <QThread>
    #include <QMutex>
    #include <serial.h>
    
    class MyThread : public QThread
    {
       Q_OBJECT
    
    public slots:
        void stopRunning();
    
    protected:
       virtual void run();
    
    signals:
       void signalValueUpdated(QString);
    
    private:
        bool isRunning;
        Serial sTest;
    
    };
    #endif
    
    //.cpp:
    #include "MyThread.h"
    #include <QString>
    #include "Serial.h"
    #include <QDebug>
    #include <QImage>
    #include <QPixmap>
    
    
    void MyThread::run()
    {
        qDebug("Thread id inside run %d",(int)QThread::currentThreadId());
    
        isRunning = 1;
    
        uint8_t Cmd[] ={0x05, 0x07, 0xFF, 0xF0, 0x01,0x00, 0x6A, 0x50};
    
        sTest.Openport();
    
        while(isRunning == 1)
        {
            if (sTest.OpenFlag){
    
            QString string = sTest.RxTx(Cmd);
    
            msleep(1);
    
            emit signalValueUpdated(string);
            }
        }
    }
    
    void MyThread::stopRunning()
    {
        isRunning = 0;
        sTest.ClosePort();
    
    }
    

    mainwindow class:

    //.h:
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include "MyThread.h"
    #include <QDebug>
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
        void Inventory(QString response);
    
    private:
        Ui::MainWindow *ui;
        MyThread thread;
    
    };
    
    #endif // MAINWINDOW_H
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    //.cpp:
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QObject::connect(ui->startBut,SIGNAL(clicked()),&thread,SLOT(start()), Qt::QueuedConnection);
        QObject::connect(ui->stopBut,SIGNAL(clicked()),&thread,SLOT(stopRunning()), Qt::QueuedConnection);
        QObject::connect(&thread,SIGNAL(signalValueUpdated(const QString&)),this,SLOT(Inventory(const QString&)), Qt::QueuedConnection);
    
    
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void  MainWindow::Inventory(QString response)
    {
    
        if(response=="c"){
         //
       ///
    }
    
    
    }
    
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      You are using a mix of QString and const QString &
      Make sure the signal and slot are 100% the same

      I 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        You are using a mix of QString and const QString &
        Make sure the signal and slot are 100% the same

        I Offline
        I Offline
        isan
        wrote on last edited by isan
        #3

        @mrjj Hi
        I edited it and set all to QString but I still get this error when run the program

        in main window:

        //.h: 
        void Inventory(QString response);
        //.cpp:
        QObject::connect(&thread,SIGNAL(signalValueUpdated(QString)),this,SLOT(Inventory( QString)), Qt::QueuedConnection);
        
        
        void  MainWindow::Inventory(QString response)
        {
        /// 
        //
        }
        

        in thread :

        //.h:
        void signalValueUpdated(QString);
        //.cpp:
        QString string;
        emit signalValueUpdated(string);
        
        mrjjM 1 Reply Last reply
        0
        • I isan

          @mrjj Hi
          I edited it and set all to QString but I still get this error when run the program

          in main window:

          //.h: 
          void Inventory(QString response);
          //.cpp:
          QObject::connect(&thread,SIGNAL(signalValueUpdated(QString)),this,SLOT(Inventory( QString)), Qt::QueuedConnection);
          
          
          void  MainWindow::Inventory(QString response)
          {
          /// 
          //
          }
          

          in thread :

          //.h:
          void signalValueUpdated(QString);
          //.cpp:
          QString string;
          emit signalValueUpdated(string);
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @isan
          Hi
          Try to delete your build folder and then run rebuild all.
          Seems ok now.

          I 1 Reply Last reply
          1
          • mrjjM mrjj

            @isan
            Hi
            Try to delete your build folder and then run rebuild all.
            Seems ok now.

            I Offline
            I Offline
            isan
            wrote on last edited by
            #5

            @mrjj I did this, but it didn't make any difference

            QObject::connect: No such slot MainWindow::Inventory( QString) in ..\Inv\mainwindow.cpp:12
            QObject::connect:  (receiver name: 'MainWindow')
            
            1 Reply Last reply
            0
            • GerhardG Offline
              GerhardG Offline
              Gerhard
              wrote on last edited by
              #6

              In mainwindow.h try :
              protected Slots:
              void Inventory(QString response);

              Gerhard

              I 1 Reply Last reply
              2
              • GerhardG Gerhard

                In mainwindow.h try :
                protected Slots:
                void Inventory(QString response);

                I Offline
                I Offline
                isan
                wrote on last edited by
                #7

                @gerhard tnx

                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