void MainWindow::MakineStatR(int realStat) { QTimer::singleShot(150, this, SLOT(MakineStatR1));}



  • {ubuntu 14.04 Qt5.6} In my main I have these fun:

    I use directly in

    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    

    some other QTimer::singleshot with succes (there is not a "classic" QOBJECT related issue.... )

    but in other sub-fun ... example:

    void MainWindow::MakineStatR(int realStat) { QTimer::singleShot(150, this, SLOT(MakineStatR1));}
    void MainWindow::MakineStatR1() { emit sendInOutMachine(45); }
    

    not work at all and return these error:

    QObject::connect: Parentheses expected, slot MainWindow::MakineStatR1 in ...
    QObject::connect:  (receiver name: 'MainWindow')
    

    Why these??

    Regards
    Giorgio


  • Moderators

    Hi @gfxx ,
    As exactly the error says you are missing the parentheses in here:
    { QTimer::singleShot(150, this, SLOT(MakineStatR1));}
    Should be
    { QTimer::singleShot(150, this, SLOT(MakineStatR1()));}

    Btw. you can use C++11 features to avoid the parentheses.

    QTimer::singleShot(150, this, &MainWindow::MakineStatR1)



  • sorry.... an stupyd error during test ..... the error show me with the Parentheses is :

    QObject::connect: object not sxist ... or similar ... 
    
    

    (sorry now im out of office )
    referred to the fact that Void not exist in MaiWindows ..... but it exist .... and Q_OBJECT is declared in mainwindows.h....

    today i think can post the right error show

    regards
    giorgio


  • Moderators

    @gfxx Alright, Post the exact error.



  • @p3c0 real code with problem

    void MainWindow::MakineStatR(int realStat) { QTimer::singleShot(150, this, SLOT(MakineStatR1(realStat)));}
    void MainWindow::MakineStatR1(int realS1) { emit sendInOutMachine(realS1); }
    

    real error ...

    QObject::connect: No such slot MainWindow::MakineStatR1(realStat) in ../KYC-C/mainwindow.cpp:1862
    QObject::connect:  (receiver name: 'MainWindow')
    thread5 command:   101
    

    yesterday i've test without passing int value to void..... it works..... with value passing i receive these error.....

    regards
    giorgio


  • Qt Champions 2016

    @gfxx said:
    Hi
    The timeout() signal of QTimer do not take a parameter
    so
    void MainWindow::MakineStatR(int realStat) {
    QTimer::singleShot(150, this, SLOT(MakineStatR1(realStat)));
    }

    Is not possible as QTimer then would have to store your
    realStat and use that in its timeout(). If it had a paramter.

    So in short you cannot pass parameters that way as far as i know :)


  • Moderators

    realStat is a state. The timer will fire after some time (after you left the scope of realStat), so you need to preserve that state somewhere. You can use a lambda object for that:

    void MainWindow::MakineStatR(int realStat) {
        QTimer::singleShot(150, [=]{ MakineStatR1(realStat); });
    }
    


  • @Chris-Kawa said:

    realStat is a state. The timer will fire after some time (after you left the scope of realStat), so you need to preserve that state somewhere. You can use a lambda object for that:

    realStat is the number of modbus register that i call for cofirm after sending modbus command. after every sending command (from pusch button in gui) i control the execution via register. my gui is client modbus that control remote machine (server).
    I need to send command from a void and request of machineStat from other one valid for all command and calling from pushbutton void.....

    regards
    giorgio


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.