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. Signals & Slots Question

Signals & Slots Question

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.6k Views 3 Watching
  • 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.
  • Z Offline
    Z Offline
    zeroptr
    wrote on last edited by
    #1

    Hi all,

    I have a simple class like this

    #include <QObject>
    
    class vitem : public QObject
    {
        Q_OBJECT
    public:
        explicit vitem(QObject *parent = 0);
        void setboolvalue(bool value);
        void setintvalue(int ideger);
    private:
        bool b_value = false;
        int i_value = 0;
    
    signals:
        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
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private slots:
    
    
        void on_btnDENE_clicked(bool checked);
    
    private:
        Ui::MainWindow *ui;
        vitem *theItem;
    };
    ui->setupUi(this);
        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??

    Linux Mint 20.04 64 Bit QT6.0.1

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How do you know it's not connected ?

      When are you changing the value of your vitem object ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zeroptr
        wrote on last edited by
        #3

        sorry..

        it says

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

        and

        I put another button and whan clicked

        void MainWindow::on_btnDENE_clicked(bool checked)
        {
        theItem->setboolvalue(checked);
        }

        Linux Mint 20.04 64 Bit QT6.0.1

        FlotisableF 1 Reply Last reply
        0
        • Z zeroptr

          sorry..

          it says

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

          and

          I put another button and whan clicked

          void MainWindow::on_btnDENE_clicked(bool checked)
          {
          theItem->setboolvalue(checked);
          }

          FlotisableF Offline
          FlotisableF Offline
          Flotisable
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          2
          • Venkatesh VV Offline
            Venkatesh VV Offline
            Venkatesh V
            wrote on last edited by
            #5

            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));

            Z 1 Reply Last reply
            1
            • Venkatesh VV Venkatesh V

              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));

              Z Offline
              Z Offline
              zeroptr
              wrote on last edited by
              #6

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

              Linux Mint 20.04 64 Bit QT6.0.1

              1 Reply Last reply
              0
              • Venkatesh VV Offline
                Venkatesh VV Offline
                Venkatesh V
                wrote on last edited by
                #7

                Hi @zeroptr

                Sorry try this,

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

                reply quote 0

                Z 1 Reply Last reply
                4
                • Venkatesh VV Venkatesh V

                  Hi @zeroptr

                  Sorry try this,

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

                  reply quote 0

                  Z Offline
                  Z Offline
                  zeroptr
                  wrote on last edited by
                  #8

                  @Venkatesh-V

                  Thank's a lot solved :)

                  Linux Mint 20.04 64 Bit QT6.0.1

                  1 Reply Last reply
                  0

                  • Login

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