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. Emit Signal when Variable Changes Value

Emit Signal when Variable Changes Value

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.8k Views 1 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.
  • R Offline
    R Offline
    retro_code
    wrote on last edited by
    #1

    I'd like to emit a signal when a int variable changes value. The value of the int variable comes from an external application so I have no control over it or when it will change.

    I've read through the documentation and tried to implement the following:

    @//From MainWindow.h header file:
    //******************************//
    signals:
    void StateChangedFromActive();

    public slots:
    void CheckState();
    //*****************************//

    // FROM MainWindow.cpp function
    ////
    QObject::connect(this, SIGNAL(StateChangedFromActive()), this, SLOT(CheckState()));
    //
    //

    //From MainWindow::CheckState function
    ////
    void MainWindow::CheckState()
    {
    if(CNC_STATE != 4) //CNC_STATE is a global variable for prototyping
    {
    emit StateChangedFromActive();
    ui->ModeButtonStation->setEnabled(true);
    }
    }
    //
    //@

    So, basically I want to set a QToolButton as enabled whenever the CNC_STATE global changes from 4. I haven't found an example that shows how to emit a signal from something that isn't a QWidget.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Hi retro_code.
      First of all i didn’t understand how external app can change your variable without your permission.
      But, if your class should support signal and slots you need inherit it from QObject. For example:
      @class SomeClass: public QObject
      {
      Q_OBJECT
      ....
      signals:
      void StateChangedFromActive();

      public slots:
          void CheckState();
      

      }@

      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