1

I am writing an application with a submit button but I want to check if the textfield has been filled if not do not submit.

Not quite sure how the code should go.

My code currently looks like

if(flightNumber == NULL)
{
   flightNumbertext.text.color = 'red';
}

I am designing this for a Qt Quick application written in QML.

4
  • Check the docs for the widget you're using for flightNumber. If it's a QLineEdit, for example, check its text() property. Commented Jun 30, 2011 at 7:19
  • hi please is there anyway I can check the input in an email field fulfills the conditions for being a valid email address. Commented Jun 30, 2011 at 7:24
  • See stackoverflow.com/questions/1778390/… Commented Jun 30, 2011 at 7:59
  • I managed to edit the code and the following does work (flightNumber.text.length == 0) but leaves a loop hole in that it allows white spaces to be considered as values. Trying to use the isEmpty or iNull so far results in an error telling me flightNumber isn't a function which I kind of agree with but just can't figure out my way around this since using QTQuick Commented Jun 30, 2011 at 8:44

2 Answers 2

4

QT's editing widgets use QString.

QString has many methods that you can use.

Use isEmpty or isNull methods of QString.

I hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I managed to edit the code and the following does work (flightNumber.text.length == 0) but leaves a loop hole in that it allows white spaces to be considered as values. Trying to use the isEmpty or iNull so far results in an error telling me flightNumber isn't a function which I kind of agree with but just can't figure out my way around this since using QTQuick
0

After a bit of playing, I think this will work for you

if (flightNumber.text.trim().length == 0) {
    flightNumbertext.text.color = 'red'; 
}

The function trim() is like QString::trimmed(). It removes both leading and trailing spaces from the string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.