0

I'm not sure how to make the loop wait and iterate with a different input.

For example:

DO
{
// DO STUFF


}WHILE (Whatever is in lineEdit widget is not 'N') // User picks between Y and N

However, I can't seem to implement any way to wait at the end of the do part so that the user can edit the lineEdit text content.

AAEM
  • 1,837
  • 2
  • 18
  • 26
Louis93
  • 3,843
  • 8
  • 48
  • 94
  • Do you mean the loop should run every time a non-N character is entered? Or do you mean that something else would run in an entirely different thread until N is entered? – Anthony May 15 '12 at 23:29
  • You should use QT's signals and listen to the change event. – lucas clemente May 15 '12 at 23:34

1 Answers1

3

In Qt, you would do nothing. Let the QApplication event loop do its thing. Just connect a handling slot to QLineEdit's textEdited(const QString & text ) signal.

class MyObject : public QObject
{
Q_OBJECT
public:
   MyObject();
   ~MyObject();

private slots:
   void handleUserInput(const QString& text);

private:
   QLineEdit* lineEdit_;
};

MyObject::MyObject()
   : lineEdit_(new QLineEdit)
{
   connect(lineEdit_, SIGNAL(textEdited(const QString&)), 
           this, SLOT(handleUserInput(const QString&)));
}

MyObject::~MyObject()
{
   delete lineEdit_;
}

void MyObject::handleUserInput(const QString& text)
{
   if(text != "desiredText") 
      return;

   // do stuff here when it matches
}
cgmb
  • 4,284
  • 3
  • 33
  • 60
  • Cool, thanks for the insight. Also, doesn't the textEdited send signals constantly every time the text is changed? Wouldn't you think something like editingFinished() for longer strings? I just want to know why you would pick textEdited over editingFinished. Thank you once again. – Louis93 May 15 '12 at 23:42
  • 1
    You're right. textEdited would fire repeatedly as the user enters his text. I used that in this example because I thought that was what you were looking for. If you'd rather wait until the user has finished making all his changes before handling the input, editingFinished is the signal you'd want to connect to. – cgmb May 15 '12 at 23:47