Results 1 to 15 of 15

Thread: QCheckBox example?

  1. #1
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default QCheckBox example?

    Hi,

    I am using qtcreator and having some trouble with qcheckbox. I added it using qtcreator and basically what I want to do is when the checkbox is checked, i would like QProcess (it is an external app on windows os) which is about to run, to accept an arg. So, what kind of statement would make this work? I tried a few but it didn't work yet. Please reply with precise examples thanks in advance.

    Here is part of the code.

    if (ui->check2pass->isChecked()){
    args << "-pass"; args << "2";

    }
    commandProcess.start("C:/ffmpeg.exe",args);

    "check2pass" is the checkbox in the gui.

  2. #2
    Join Date
    Dec 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    Please use the CODE tag for readability in the future


    Qt uses Signals and Slots so you can connect the UI with your application.
    You may find this tutorial helpful.

    You can use the + button in the Designer mode to connect a checkBox clicked() Signal to a Slot which you write (and document as a slot in your header file).

    Hope that helps.

  3. #3
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    Hi,

    Thanks for your reply. Could you provide a code example? Right now I have this:

    Qt Code:
    1. void newprogram::twopass()
    2. {
    3.  
    4.  
    5.  
    6. args << "-pass"; args << "2";
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    I created a checkbox in the gui designer, made a signal/slot clicked feature, put in the header file


    private slots:
    void twopass();

    and have the above code, I'm not too sure what I need to make it so the checkbox is clicked and something is to happen-i'd also like to add some args to it as well.
    Last edited by Milardo; 8th December 2010 at 07:02.

  4. #4
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QCheckBox example?

    How did you connect the checkbox with the slot? A little more of your code would help.

    Your code example doesn't start a new process. It only fills args with some arguments.
    Also, make sure that the program that must be started, c:/ffmpeg.exe, can be found by the calling program.

  5. #5
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    Hi,

    Using qt creator design mode, i connected the checkbox to the slot. That is already done. I'm not trying to start a new process, actually i would like to use the checkbox, when checked, will enable an option that will (with args i think) be passed to ffmpeg which will be started when ones click a button. So far, I can't seem to get the checkbox, when checked, to pass those args as options for ffmpeg to use. Any examples of that would be helpful as I can't really find good ones.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCheckBox example?

    You already have the code. Connect the signal from whatever widget the user uses to actually attempt to start the program to a slot containing the code from your first post. You do not need to connect the checkbox to anything unless you want the program to launch every time the checkbox is clicked.

    Qt Code:
    1. // slot
    2. void goForthAndExecute()
    3. {
    4. // QProcess commandProcess;
    5.  
    6. if (ui->check2pass->isChecked()){
    7. args << "-pass"; args << "2";
    8. }
    9. commandProcess.start("C:/ffmpeg.exe",args);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 9th December 2010 at 05:17.

  7. #7
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    I have QProcess commandProcess; in my header file already. I have something like
    [CODE]
    void Encode ()
    {

    QStringList args;

    args << "-i";
    args << "-ac"; args << ui->comboResolution->currentText();


    if (ui->check2pass->isChecked()){

    args << "-pass"; args << "2";

    }

    commandProcess.start("C:/ffmpeg.exe",args);

    }
    [CODE]

    I believe it didn't work though the checkbox args weren't recognized. What do you think I am missing?
    Last edited by Milardo; 9th December 2010 at 04:56.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCheckBox example?

    What triggers a call to Encode()?

  9. #9
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    that would be a pushbutton in the gui, basically i check the box, and i want to when i push the Encode button that checkbox args to be applied.

  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCheckBox example?

    Have you connected the clicked() signal of the push button to this slot?

  11. #11
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    yes i have

  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCheckBox example?

    Well then, you need to put a breakpoint in the slot and single step through it checking that it follows the path you are expecting and that everything has the values you are expecting.

  13. #13
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    yeah i will check it again but everything worked correctly except my "if" statements regarding checkbox

  14. #14
    Join Date
    Dec 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    So if you write
    Qt Code:
    1. if (ui->check2pass->isChecked()){
    2. args << "-pass"; args << "2";
    3. } else {
    4. qDebug("Failed Event.");
    5. }
    To copy to clipboard, switch view to plain text mode 

    It will print out Failed Event?

  15. #15
    Join Date
    Sep 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCheckBox example?

    sorry i can't verify that as i'm on a different computer now but i will try that any other suggestions would be welcome.

Similar Threads

  1. About QCheckBox
    By liushuo0826 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 16th April 2010, 06:14
  2. QCheckBox in QTreeWidget
    By Kode.Cooper in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2010, 05:55
  3. QCheckBox value
    By Koas in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2009, 13:33
  4. Read-only QCheckBox
    By alu23 in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2008, 16:25
  5. QCheckbox
    By sonuani in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2008, 13:12

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.