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
Forum Updated to NodeBB v4.3 + New Features

Emit Signal when Variable Changes Value

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.6k 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 10 Jul 2013, 00:07 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 10 Jul 2013, 05:57 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

      1/2

      10 Jul 2013, 00:07

      • Login

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