Connect setMode() to a button



  • Hi, this is my first post,I were progamming on qt for school,and I have to connect the setMode of a QLCDNumber to a button,
    What is wrong?

    (QLCDNumber *D;
    D=new QLCDNumber(8);)

    @connect("button", SIGNAL(clicked()), D, SLOT(setMode(Hex)));@

    I tried to write D->Value(), but..nothing..


  • Moderators

    Hi, welcome to devnet.

    That's not how it works. the first argument is not a string, it's an object pointer.
    SLOT is a text macro. You can't pass arguments at connect site with it.

    If you're using a c++11 compiler the simplest would be to connect a lambda:
    @
    //D is a terrible name so I'll just use something else
    QLCDNumber* lcd = new QLCDNumber(8);
    QPushButton* button = new QPushButton("Set hex mode");

    connect(button, &QPushButton::clicked, ={
    lcd->setMode(QLCDNumber::Hex);
    });
    @
    If you can't use c++11 then you need to create a function in your class and connect to that.


Log in to reply
 

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