Results 1 to 10 of 10

Thread: A few questoins about Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default A few questoins about Qt

    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:
    Qt Code:
    1. if(cloudCheckBox->checkState()==Qt::Checked);
    2. {
    3. for(size_t i=9;i<17;++i)
    4. {
    5. trimCloud(list[i]);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Qt Code:
    1. cloudCheckBox->setChecked(true);
    2. windSpeedCheckBox->setChecked(true);
    To copy to clipboard, switch view to plain text mode 

    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!
    Last edited by HelloDan; 22nd February 2009 at 09:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: A few questoins about Qt

    Quote Originally Posted by HelloDan View Post
    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?

  3. The following user says thank you to Lykurg for this useful post:

    HelloDan (22nd February 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: A few questoins about Qt

    Quote Originally Posted by HelloDan View Post
    3 My code fragment is showed as the following:
    Qt Code:
    1. if(cloudCheckBox->checkState()==Qt::Checked);
    2. {
    3. for(size_t i=9;i<17;++i)
    4. {
    5. trimCloud(list[i]);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    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().

  5. The following user says thank you to Lykurg for this useful post:

    HelloDan (22nd February 2009)

  6. #4
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A few questoins about Qt

    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.

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A few questoins about Qt

    Add CONFIG+=console to your project file and rerun qmake.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    HelloDan (22nd February 2009)

  9. #6
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A few questoins about Qt

    I don't know how to correct the cloudCheckBox->checkState()==Qt::Checked problem.
    Can anyone give some tips?

  10. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: A few questoins about Qt

    What do you want achieve? And when do you call the function which is checking the state of the box?

  11. #8
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A few questoins about Qt

    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!

  12. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: A few questoins about Qt

    your constructor:
    Qt Code:
    1. QObject::connect(cloudCheckBox, SIGNAL(toggled(bool)), this, SLOT(yourSlot(bool));
    To copy to clipboard, switch view to plain text mode 

    and then

    Qt Code:
    1. void YourClass::yourSlot(bool checked)
    2. {
    3. if (checked) {
    4. // do what ever you want
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

  13. #10
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A few questoins about Qt

    if(cloudCheckBox->checkState()==Qt::Checked);


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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.