PDA

View Full Version : A few questoins about Qt



HelloDan
22nd February 2009, 09:50
1 By default, that's not a minimize button in the Qt widget in windows, but a help ("?" symbol) button. If I want to add a minimize button for a dialog at the same remove the help symbol. What I should do.

2 Why I write a file in the patten in a console window:
QFile file("C:\abc\test.txt");
it doesn,t work. But it work in this way : QFile file("C:\\abc\\test.txt"); At the same time, I get the file name from QFileDialog::getOpenFileName and do not need to replace '\' with "\\". and it work fine. Why?

3 My code fragment is showed as the following:


if(cloudCheckBox->checkState()==Qt::Checked);
{
for(size_t i=9;i<17;++i)
{
trimCloud(list[i]);
}
}

It's strange that even I do not click the CheckBox, but it still execute the above code fragment. I try cloudCheckBox->isChecked() instead, I got the same result. Why?

By the way, in the constructor function, I set the CheckBox true.


cloudCheckBox->setChecked(true);
windSpeedCheckBox->setChecked(true);


When i run the app, I click to remove the "√".



4 From my perspective, I do think that try my thinking in a console window is very useful. Also because that I don't know how to test my code in a GUI program, it's very trival.
How do you solve this problem?

Thanks! Any relpy is appreciated!

Lykurg
22nd February 2009, 09:56
1 By default, that's not a minimize button in the Qt widget in windows, but a help ("?" symbol) button. If I want to add a minimize button for a dialog at the same remove the help symbol. What I should do.

Qt::WindowFlags


2 Why I write a file in the patten in a console window:
QFile file("C:\abc\test.txt");
it doesn,t work. But it work in this way : QFile file("C:\\abc\\test.txt"); At the same time, I get the file name from QFileDialog::getOpenFileName and do not need to replace '\' with "\\". and it work fine. Why?

escaping?

Lykurg
22nd February 2009, 10:00
3 My code fragment is showed as the following:


if(cloudCheckBox->checkState()==Qt::Checked);
{
for(size_t i=9;i<17;++i)
{
trimCloud(list[i]);
}
}

It's strange that even I do not click the CheckBox, but it still execute the above code fragment. I try cloudCheckBox->isChecked() instead, I got the same result. Why?


checkState() is a state not an action. If you want react on user actions use signal and slots. (By the way, maybe you want use QAbstractButton::isChecked().)



4 From my perspective, I do think that try my thinking in a console window is very useful. Also because that I don't know how to test my code in a GUI program, it's very trival.
How do you solve this problem?

I don't understand the question. For debugging a GUI use gdb or simple qDebug().

HelloDan
22nd February 2009, 10:04
qDebug().

How to use qDebug()? I try it in the console window, it's OK. But I try in a GUI program, I can see nothing.

wysota
22nd February 2009, 10:55
Add CONFIG+=console to your project file and rerun qmake.

HelloDan
22nd February 2009, 11:21
I don't know how to correct the cloudCheckBox->checkState()==Qt::Checked problem.
Can anyone give some tips?

Lykurg
22nd February 2009, 11:24
What do you want achieve? And when do you call the function which is checking the state of the box?

HelloDan
22nd February 2009, 11:32
I'm sorry. My English is really very limited.

What i want to achive is that if the cloudCheckBox has a "√" (it's checked.), then execute the code. otherwise, do nothing.

but the following code line seem that it always true, even i remove the "√"
if(cloudCheckBox->isChecked());

Why? how to solve the problem. Thanks!

Lykurg
22nd February 2009, 11:40
your constructor:


QObject::connect(cloudCheckBox, SIGNAL(toggled(bool)), this, SLOT(yourSlot(bool));


and then


void YourClass::yourSlot(bool checked)
{
if (checked) {
// do what ever you want
}
}

HelloDan
22nd February 2009, 12:13
if(cloudCheckBox->checkState()==Qt::Checked);


Thank! It's a very stupid mistake. remove ; will be ok