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. State machine transitions custom signals
QtWS25 Last Chance

State machine transitions custom signals

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

    In my program I have three classes. One that controls a QProcess(mplayer class) which I want to emit signals whenever certain sections of the code is hit. A wrapper class which sets the windows layout. And a window class which controls the state machine.To test this state machine i used a clicked signal from some pushbuttons (which worked fine), however when i now try to emit two custom signals it states:

    bq. QState::addTransition: no such signal QPushButton::mplayer::Running()

    bq. QState::addTransition: no such signal QPushButton::mplayer::Not_Running()

    The main section of the state machine in window class (top class) window.cpp
    @ Current_State = new QLabel;
    Current_State->setText("NO STATE");
    Current_State->resize(50,50);

    Not_Running = new QState();
    Initialised = new QState();
    Running = new QState();
    Not_Running->assignProperty(Current_State, "text", "Not_Running");
    Initialised->assignProperty(Current_State, "text", "Initialised");
    Running->assignProperty(Current_State, "text", "Running");
    
    
    //Not_Running->addTransition(button2, SIGNAL(clicked()),Initialised);
    Initialised->addTransition(mplayer, SIGNAL(mplayer::Running()),Running);
    Running->addTransition(mplayer, SIGNAL(mplayer::Not_Running()),Initialised);
    
    /* States are added in state machine */
    
    //machine.addState(Not_Running);
    machine.addState(Initialised);
    machine.addState(Running);
    
    /*  Set the state initial for the state machine */
    
    machine.setInitialState(Initialised);
    
    /* Start the state machine */
    
    machine.start();@
    

    mplayer class which is the cpp file i want to emit signals from(bottom class) mplayer.cpp.
    @ this->m_process->setProgram(program);
    this->m_process->setArguments(arguments);

    this->m_process->start();
    
    if(this->m_process->state()==QProcess::Running)
    {
        qDebug("\nSuccess in starting Process = Mplayer");
        emit Running();
    }
    if(!this->m_process->waitForStarted())
    {
        qDebug("\nFailed To start Process = Mplayer");
    }
    

    }

    mplayer::~mplayer()
    {
    qDebug("\nDeleting Process = Mplayer");
    emit Not_Running();
    this->m_process->close();
    }
    @

    mplayer.h
    @#ifndef MPLAYER_H
    #define MPLAYER_H

    #include <QWidget>
    #include <QProcess>

    class mplayer : public QWidget
    {
    Q_OBJECT
    public:
    explicit mplayer(QWidget *parent = 0);
    ~mplayer();

    signals:
    void Running();
    void Not_Running();
    void Initialised();

    private:
    QString program = "C:\Users\Downloads\mplayer\mplayer.exe";
    QStringList arguments;
    QProcess *m_process;

    };

    #endif // MPLAYER_H@

    If anyone has any ideas what im doing wrong please let me know thanks.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ion_knight
      wrote on last edited by
      #2

      Just realised that in my transition I had button2 which I removed and replaced with mplayer (which just give me an error(error: expected primary-expression before ',' token). However will I need to make mplayer class a child of mplayer_wrapper and mplayer_wrapper a child of window ? is there any other way to reference mplayer class from window (as really they shouldn't be children as they have no real relationship to each other).

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        bq. I need to make mplayer class a child of mplayer_wrapper and mplayer_wrapper a child of window ? is there any other way to reference mplayer class from window

        How is the current relation of objects ? How are you accessing them ? If you give good details it will help us. Also this question is different from original post, it is good to put a new question with good details.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        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