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. Creating QGenericArgument

Creating QGenericArgument

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

    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?

    sierdzioS 1 Reply Last reply
    0
    • C column

      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?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @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
      4

      • Login

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