PDA

View Full Version : QCheckBox example?



Milardo
5th December 2010, 03:28
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.

artoonie
5th December 2010, 08:17
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 (http://doc.trolltech.com/4.7/signalsandslots.html) 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.

Milardo
8th December 2010, 06:57
Hi,

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


void newprogram::twopass()
{


QStringList args;

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

}

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.

boudie
8th December 2010, 14:04
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.

Milardo
9th December 2010, 03:16
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.

ChrisW67
9th December 2010, 04:26
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.



// slot
void goForthAndExecute()
{
// QProcess commandProcess;
QStringList args;

if (ui->check2pass->isChecked()){
args << "-pass"; args << "2";
}
commandProcess.start("C:/ffmpeg.exe",args);
}

Milardo
9th December 2010, 04:51
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?

ChrisW67
9th December 2010, 05:15
What triggers a call to Encode()?

Milardo
9th December 2010, 05:36
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.

ChrisW67
9th December 2010, 06:02
Have you connected the clicked() signal of the push button to this slot?

Milardo
9th December 2010, 06:15
yes i have

ChrisW67
9th December 2010, 06:33
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.

Milardo
9th December 2010, 06:41
yeah i will check it again but everything worked correctly except my "if" statements regarding checkbox

artoonie
9th December 2010, 07:25
So if you write

if (ui->check2pass->isChecked()){
args << "-pass"; args << "2";
} else {
qDebug("Failed Event.");
}


It will print out Failed Event?

Milardo
9th December 2010, 07:36
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.