Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:31:49+00:00 2026-06-17T10:31:49+00:00

I am trying to create a program that waits for the user to input

  • 0

I am trying to create a program that waits for the user to input something into a line edit widget, and when they hit enter, I want to compare the value to some predefined one (for example “1”). The problem I seem to be having is that I cannot find a way to make this work with the QStateMachine. At the moment, it will wait for the user to press enter and it just switches over to the next state, but I want it to only go to the next state if the input is “1”. Here is the code I am using and thank you for any help that you can offer.

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(someSlot()));
    setupStateMachine();
}

...

void MainWindow::setupStateMachine()
{
    QStateMachine *machine = new QStateMachine(this);
    QState *s1 = new QState();
    QState *s2 = new QState();
    QState *s3 = new QState();

    s1->assignProperty(ui->label, "text", readFile("intro.txt"));
    s2->assignProperty(ui->label, "text", "In state s2");
    s3->assignProperty(ui->label, "text", "In state s3");

    s1->addTransition(this, SIGNAL(editing()), s2);
    s2->addTransition(this->ui->pushButton, SIGNAL(clicked()), s3);
    s3->addTransition(this->ui->pushButton, SIGNAL(clicked()), s1);

    machine->addState(s1);
    machine->addState(s2);
    machine->addState(s3);
    machine->setInitialState(s1);

    machine->start();

    qDebug() << "State Machine Created";
}

...

void MainWindow::someSlot()
{
    if(ui->lineEdit->text() == "1")
    {
        emit editing();
    }
}

In the header file:

{
...
signals:
    void editing();
...
private slots:
    void someSlot();
...
};

PS: I realize that the signal does not do what I want, but I can’t figure out which signal to use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:31:50+00:00Added an answer on June 17, 2026 at 10:31 am

    Perhaps you can connect editingFinished to your own slot. In that slot, check if the input is “1”. if so, emit a new signal you pass into addTransition instead of editingFinished

    To add a signal to a class, change the class like this (make sure there is a Q_OBJECT declared at the very top of the class):

    signals:
        void mySignalName();
    

    Signals are guaranteed protected. You don’t write the body of the function. That’s what MOC does. So, when you want to call the signal in your class, just call:

    emit mySignalName();
    

    emit is just for code documentation. It’s #defined to nothing. MOC will generate the body of mySignalName and boil down to calls to the slots you connect it to using QObject::connect.

    To add a new slot to your class, add this:

    private slots:
        void mySlotName();
    

    Note that you will have to write the body of a slot.

    void MainWindow::mySlotName()
    {
        if(myLineEdit->text() == "1")
            emit mySignalName();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a program that will be passed input data from
I'm trying to create a simple program that waits for a file using sockets
I am trying to create a program that will get data directly from socket
I'm trying to create a program that takes a text file of c++ code
I am trying to create a program that will do some simple calculations, but
I am trying to create a program that has one tableview and when you
I'm currently trying to create a program that estimates location based on signal strength.
I'm trying to create a c program that implements the radon transform algorithm. I
I am trying to create a Jenkins job that restarts a program that runs
I have a small program that I'm trying to create to get ip addresses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.