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. QObject::connect: No such slot MainWindow::getThing(ctx)
Forum Updated to NodeBB v4.3 + New Features

QObject::connect: No such slot MainWindow::getThing(ctx)

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 175 Views 1 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.
  • G Offline
    G Offline
    grepAns
    wrote on last edited by
    #1

    I am trying to create a GUI that interfaces with a redis server to get key values and display them in the GUI. When I build and run the code, I get an error:
    QObject::connect: No such slot MainWindow::getThing(ctx).

    After looking at the stack overflow answers, I still don't understand why my GUI can't recognize the slot that I created.

    Main.cpp

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

    MainWindow.cpp

    include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "hiredis/hiredis.h"
    #include <string>
    #include <iostream>
    #include <QString>
    #include <QTimer>
    #include <QVector>
    #include <QListWidget>
    #include <QDateTime>
    #include <QFileDialog>
    #include <pthread.h>
    #include <QtConcurrent>
    
    QString getRedisValue(redisContext *ctx, QString cmdPrefix, QString keyName);
    void getThing(redisContext *ctx);
    
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        setWindowTitle(tr("Vorrina"));
        //Establish redis connection
        redisContext *ctx = redisConnect("127.0.0.1", 6379);
        if (ctx != NULL && ctx->err){
                printf("Error: %s\n", ctx->errstr);
                // handle error
        }
        //ui->label->setText("Hello");
    
        timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(getThing(ctx)));
        timer->start(1000);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    QString MainWindow::getRedisValue(redisContext *ctx, QString cmdPrefix, QString keyName){
        QString cmd= cmdPrefix + keyName;
        QByteArray cmdBytes = cmd.toLocal8Bit();
        redisReply *reply;
        void *pointer = NULL;
        pointer = redisCommand(ctx, cmdBytes.constData());
        reply = (redisReply*)pointer;
        QString keyValue = QString(reply->str);
        freeReplyObject(reply);
        return keyValue;
    }
    
    
    void MainWindow::getThing(redisContext *ctx){
        QString label = getRedisValue(ctx, "GET ", "answer");
        if(QString::compare(label, "ITS_HERE") == 0){
            ui->label->setText("ITS HERE");
            ui->label->setStyleSheet("QLabel { background-color : red; }");
        }
        else if(QString::compare(label, "NOT_HERE") == 0){
            ui->label->setText("NOT HERE");
            ui->label->setStyleSheet("QLabel { background-color : #90ee90; }");
        }
        else{
            ui->label->setText("LOOKING FOR IT");
            ui->label->setStyleSheet("QLabel { background-color : yellow; }");
        }
    }
    

    Mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <string.h>
    #include <hiredis/hiredis.h>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
        QString getRedisValue(redisContext *ctx, QString cmdPrefix, QString keyName);
    
    public slots:
        void getThing(redisContext *ctx);
    
    private:
        Ui::MainWindow *ui;
        QTimer *timer;
    
    };
    #endif // MAINWINDOW_H
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can't pass parameters values in your connect calls. Even more you can't do a connection from a signal with no parameters with a slot that has parameters unless they have all default values.

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

      1 Reply Last reply
      3

      • Login

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