Re: MessageBox Validation
Code:
void Autotester::clearlogs()
{
uip.AutoLog->clear();
}
Re: MessageBox Validation
Thanks Victor.
Heres my final code that works --
Code:
void Autotester::uipAutoClearlogs()
{
int answer
= QMessageBox::question(this, tr
("Autotester Log"), tr
("Are you sure you want to clear the current Autotester log?"),
QMessageBox::Yes,
QMessageBox::Cancel);
uip.AutoLog->clear();
Now, my next question is. I want to put a validation in there to check if a user clicks on the clear button when there is no text available?
I'd want a QMessageBox to appear that would state "There is no text to clear".
Would I use another if on top of the statement?
Re: MessageBox Validation
Quote:
Would I use another if on top of the statement?
Yes. To display the message, you may use QMessageBox::information().
Re: MessageBox Validation
Code:
void tester::uipEulpClearlogs()
{
if (uip.ECULPLog.isEmpty())
{
break;
}
else
uip.ECULPLog->clear();
}
I'm getting the error
-
1>.\tester.cpp(1431) : error C2228: left of '.isEmpty' must have class/struct/union
1> type is 'QTextEdit *'
1> did you intend to use '->' instead?
Re: MessageBox Validation
As the compiler suggests, you have to use -> because uip.ECULPLog is a pointer to an object, not an object itself.
Code:
if (uip.ECULPLog->isEmpty())
Re: MessageBox Validation
I tried that before and got this error.
1>.\tester.cpp(1431) : error C2039: 'isEmpty' : is not a member of 'QTextEdit'
1> c:\qt\4.5.1\include\qtgui\../../src/gui/widgets/qtextedit.h(70) : see declaration of 'QTextEdit'
1>.\tester.cpp(1434) : error C2043: illegal break
1>.\tester.cpp(1439) : error C2065: 'answer' : undeclared identifier
Re: MessageBox Validation
You also forgot the brackets:
Code:
void tester::uipEulpClearlogs()
{
if (uip.ECULPLog->isEmpty())
{
break;
}
else {
uip.ECULPLog->clear();
}
}
Re: MessageBox Validation
Quote:
I tried that before and got this error.
Oh, that's true. If it's a QLineEdit you need to call the text() method:
Code:
if (uip.ECULPLog->text().isEmpty())
Re: MessageBox Validation
It's a QTextEdit.
Code:
1>.\tester.cpp(1431) : error C2039: 'text' : is not a member of 'QTextEdit'
1> c:\qt\4.5.1\include\qtgui\../../src/gui/widgets/qtextedit.h(70) : see declaration of 'QTextEdit'
1>.\tester.cpp(1431) : error C2228: left of '.isEmpty' must have class/struct/union
1>.\tester.cpp(1434) : error C2043: illegal break
Re: MessageBox Validation
Then it's either toPlainText() or toHtml() instead of text(), depending on whether you're using rich text or plain text.