Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Creating QGenericArgument

    General and Desktop
    2
    2
    281
    Loading More Posts
    • 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.
    • C
      column last edited by

      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?

      sierdzio 1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators @column last edited by

        @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

        (Z(:^

        1 Reply Last reply Reply Quote 4
        • sierdzio
          sierdzio Moderators @column last edited by

          @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

          (Z(:^

          1 Reply Last reply Reply Quote 4
          • First post
            Last post