Important: Please read the Qt Code of Conduct -

Signals & Slots Question

  • Hi all,

    I have a simple class like this

    #include <QObject>
    class vitem : public QObject
        explicit vitem(QObject *parent = 0);
        void setboolvalue(bool value);
        void setintvalue(int ideger);
        bool b_value = false;
        int i_value = 0;
        void boolvaluechanged(bool value);
        void intvaluechanged(int ideger);
    public slots:
    vitem::vitem(QObject *parent) : QObject(parent)
    void vitem::setboolvalue(bool value)
       if(value != b_value){
           b_value = value;
           emit boolvaluechanged(value);
    void vitem::setintvalue(int ideger)
        if(ideger != i_value){
            i_value = ideger;
            emit intvaluechanged(ideger);

    and I want to connect the boolvaluechanged(bool) signal to a a forms button::setflat true;

    and I do this

    namespace Ui {
    class MainWindow;
    class MainWindow : public QMainWindow
        explicit MainWindow(QWidget *parent = 0);
    private slots:
        void on_btnDENE_clicked(bool checked);
        Ui::MainWindow *ui;
        vitem *theItem;
        theItem = new vitem;
        connect(theItem,SIGNAL(boolvaluechanged(bool)),this->ui->vlfESTERQUAD_2 ,SLOT(setFlat(bool)));

    I could not connect vitems boolvaluechanged to forms button?
    I triad many variations but no success, what am I doing wrong ?

    any help??

  • Lifetime Qt Champion


    How do you know it's not connected ?

    When are you changing the value of your vitem object ?

  • sorry..

    it says

    QObject::connect: No such slot QPushButton::setFlat(bool) in ..\Multi_proc_dene\mainwindow.cpp:10
    QObject::connect: (receiver name: 'vlfESTERQUAD_2')


    I put another button and whan clicked

    void MainWindow::on_btnDENE_clicked(bool checked)

  • @zeroptr
    QPushButton does not have a slot named setFlat, setFlat is a member function of QPushButton

    if you want to use signal and slot to set the flat property of QPushButton, maybe you can use lambda expression

  • Hi @zeroptr
    setFlat is an member fuction of QPushButton. so In your case you could have to do like this

    connect(theItem,vitem::boolvaluechanged(bool),this->ui->vlfESTERQUAD_2 ,QPushButton::setFlat(bool));

  • @Venkatesh-V said in Signals & Slots Question:

    connect(theItem,vitem::boolvaluechanged(bool),this->ui->vlfESTERQUAD_2 ,QPushButton::setFlat(bool));

    E:\VikingUretim\Multi_proc_dene\Multi_proc_dene\mainwindow.cpp:11: error: expected primary-expression before 'bool'
    connect(theItem,vitem::boolvaluechanged(bool),this->ui->vlfESTERQUAD_2 ,QPushButton::setFlat(bool));

    gives error like this..

  • Hi @zeroptr

    Sorry try this,

    connect(theItem,&vitem::boolvaluechanged,this->ui->vlfESTERQUAD_2 ,&QPushButton::setFlat);

    reply quote 0

  • @Venkatesh-V

    Thank's a lot solved :)

Log in to reply