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

Creating QGenericArgument



  • Have simple application for testing QMetaObject::invokeMethod purpose :

    #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::QueuedConnection, genericArg);
        qDebug("inv = %d\n", inv);
    }
    

    I'm getting 0 in setText value. Where 321 is gone?


  • Moderators

    @column said in Creating QGenericArgument:

        QGenericArgument genericArg =  Q_ARG(int, 321);
        bool inv = QMetaObject::invokeMethod( this,"setText",Qt::QueuedConnection, genericArg);
        qDebug("inv = %d\n", inv);
    

    I'm getting 0 in setText value. Where 321 is gone?

    Use Q_ARG directly. Do not store QGenericArgument, it won't work.

    See the docs https://doc.qt.io/qt-5/qgenericargument.html


  • Moderators

    @column said in Creating QGenericArgument:

        QGenericArgument genericArg =  Q_ARG(int, 321);
        bool inv = QMetaObject::invokeMethod( this,"setText",Qt::QueuedConnection, genericArg);
        qDebug("inv = %d\n", inv);
    

    I'm getting 0 in setText value. Where 321 is gone?

    Use Q_ARG directly. Do not store QGenericArgument, it won't work.

    See the docs https://doc.qt.io/qt-5/qgenericargument.html


Log in to reply