PDA

View Full Version : General lineEdit, converting problem



Salazaar
15th June 2007, 21:27
Hi. I've got a problem. I've got a piece of code:

if (ui.beaufortBox->isChecked() && ui.knotBox_2->isChecked())
{
QString current = ui.fromLineEdit->text();
int converted = current.toInt();

if (converted == 0)
{
ui.whiteLabel->setText("0-1");
}
}
program's contents you already know from my previous posts, but this is a new thing in it. The problem is, that when I select beaufortBox and knotBox_2 and click next step, type 0 to fromLineEdit, and click convert(which is connected to function where this code is) whiteLabel's text isn't set to 0-1. Why? Regards
edit:
but the problem isn't about value, i added

else
{
ui.whiteLabel->setText("other");
}
and still without result.

wysota
15th June 2007, 22:10
Is the slot called at all?

Salazaar
15th June 2007, 22:31
yes, it is called when user clicks convert button:

connect(ui.convertButton, SIGNAL(clicked()), this, SLOT(convert()));
The only thing which has changed since last thread, is this function:

void Dialog::convert()
{
if (ui.beaufortBox->isChecked() && ui.knotBox_2->isChecked())
{
QString current = ui.fromLineEdit->text();
int converted = current.toInt();

if (converted == 0)
{
ui.whiteLabel->setText("0-1");
}
else
{
ui.whiteLabel->setText("none");
}
}





}

wysota
15th June 2007, 22:50
But are you sure it is called? Did you verify that?

Salazaar
15th June 2007, 23:13
Verify by checking code... How can I make myself sure it is called?

wysota
16th June 2007, 03:47
Verify by checking code...
This is not enough.

How can I make myself sure it is called?
use qDebug() or QMessageBox.

Salazaar
16th June 2007, 16:06
And when I add qDebug code to my file, what is the next step to verify if it is called? And i should place qDebug at the beginning of function, right?

high_flyer
16th June 2007, 17:45
do you know what qDebug() does or what it is for?
From your questions it looks like you don't.
You should get used to reading the docs about fucntions and class you don't know.
Here is a link about deugging technics, be sure to read that.
debug

Salazaar
17th June 2007, 18:53
I read it. So I should add this line:

qDebug()<<"Dialog::convert()";
and see if compiler wrote QT_NO_DEBUG_OUTPUT right?

wysota
17th June 2007, 20:15
No. Read that fine docs again. Do you know what a compiler is and when does it work and when does it not work? Compiler is for building the application and we want to test wheter the slot is called.

Salazaar
17th June 2007, 21:08
I read docs again, but I don't understand

Salazaar
17th June 2007, 21:18
Oh, now I understand. I have to run application in console too, and if I click a button which is connected to a function and qDebug line is in this function in console appears ClassName::Function(). I checked if Dialog::convert() is called. Yes, it is called. So why my function does nothing? If you don't remember the problem, look at my #1 post

jacek
17th June 2007, 21:32
I checked if Dialog::convert() is called. Yes, it is called. So why my function does nothing?
What happens when you put that line with qDebug() inside the block that follows the first if statement (i.e. line #5 in the code from post #3)?

Salazaar
17th June 2007, 21:39
if I put qDebug() line

qDebug()<<"Dialog::convert()";
in if clause instead of at the beginning of the function, I don't reach Dialog::convert() code in console

wysota
17th June 2007, 22:03
Does the line edit contain only the "0" character? Could you post a screenshot of the line edit with the contents of the widget selected?

Salazaar
17th June 2007, 22:24
Yes, it contains only 0 character. But even if not, it should set whiteLabel to "none" text. Here's the screenshot:
http://allyoucanupload.webshots.com/v/2000141797424490087

jacek
17th June 2007, 22:25
if I put qDebug() line [...] in if clause instead of at the beginning of the function, I don't reach Dialog::convert() code in console
What does that mean?

jacek
17th June 2007, 22:29
Yes, it contains only 0 character. But even if not, it should set whiteLabel to "none" text. Here's the screenshot:
http://allyoucanupload.webshots.com/v/2000141797424490087
We already asked you several times not to post images as links to external sites. Please use attachments for this purpose.

Salazaar
17th June 2007, 22:42
We already asked you several times not to post images as links to external sites. Please use attachments for this purpose.
Does it make difference for you?

It means that this clause does not return true. Right? But why?

jacek
17th June 2007, 22:50
Does it make difference for you?
Yes, it does. The purpose of this site is not only to help people with their problems by answering questions, but also to capture knowledge, so other people can solve their problems just by searching the forum and reading past threads. If you post part of the content on the external site, it simply might get lost.


It means that this clause does not return true. Right?
Right. Now use qDebug() to see what do the both isChecked() calls return.

Salazaar
17th June 2007, 22:55
Right. Now use qDebug() to see what do the both isChecked() calls return.
How can I do it? Where to place qDebug()?

jacek
17th June 2007, 23:18
How can I do it?
I'm sure you'll find an example here (http://doc.trolltech.com/4.2/debug.html).


Where to place qDebug()?
In a place that will allow you to see the output and at the same time will guarantee that the return values are the same as the ones used in the if statement.

wysota
18th June 2007, 00:27
Yes, it contains only 0 character. But even if not, it should set whiteLabel to "none" text. Here's the screenshot:
http://allyoucanupload.webshots.com/v/2000141797424490087

The screenshot is useless. I asked you to select all the contents or better yet just add the following to your code:


qDebug() << "Line edit value:" << ui.fromLineEdit->text();

Salazaar
18th June 2007, 12:22
I reached: Line edit value: "0" But doing that doesn't make sense, my problem is that

if (ui.beaufortBox->isChecked() && ui.knotBox_2->isChecked())
doesn't return true (of course I selected this radiobuttons before) and I don't know why. In my code after user selects radiobuttons, all radiobuttons are

->setCheckable(false)
But the real mistery is when user selected two checkboxes (ui.beaufortBox and ui.knotBox_2) and clicked next step button, it sets up labels correctly (which means that this radiobuttons are checked) and after they are set to checkable(false) if clause with

if (ui.beaufortBox->isChecked() && ui.knotBox_2->isChecked())
doesn't return true. Regards

wysota
18th June 2007, 12:34
Are both buttons checked? Radio buttons are by default mutual exclusive...

Salazaar
18th June 2007, 12:37
Yes, they are both checked, they are in two different groupBoxes. But before setting it to setCheckable(false) the same if clause but in different function returned true!! Strange, isn't it? Regards

Salazaar
18th June 2007, 13:04
I've got it now! I deleted setCheckable(false) and it works. It means, that setCheckable(false) deletes current checked status.

wysota
18th June 2007, 14:27
If you change the buttons not to be checkable then no wonder they are not checked... If you want to prevent the user from changing their value, use QWidget::setDisabled() instead.

Salazaar
18th June 2007, 16:54
Marcel told me, that it saves checked() value... However, problem solved;)