Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Slot parameter for QMetaObject::invokeMethod



  • Playing with QMetaObject::invokeMethod method :

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::setText( int value)
    {
        QString s = QString::number(value);
        ui->textEdit->setText(s);
    }
    
    
    
    
    
    void MainWindow::on_pushButton_clicked()
    {
        QGenericArgument genericArg =  Q_ARG(int, 321);
        bool inv = QMetaObject::invokeMethod( this,"setText",Qt::BlockingQueuedConnection, genericArg);
        qDebug("inv = %d\n", inv);
    }
    

    QMetaObject::invokeMethod returns false.

    I'm not sure regarding slot "setText". I took it from function name and I suppose it might be related. Where I can find list of slots at all? Should I create special slot for "setText"?

    Maybe it is related to fact I run it from the same thread?


  • Lifetime Qt Champion

    Hi
    A slot is a ordinary c++ member method.
    For it to be a slot it should be listed under slots:

    class MainWindow: public QMainWindow { 
      Q_OBJECT   
    public:
    private slots:
      void MachineStatusClicked();
    public slots:
      void ShowOrderList();  
    private:
    

    so make sure you method is marked as a slot.


Log in to reply