[SOLVED] IF / ELSE strange behaving
-
So, below is my If/else statement... IF checkbox IS checked, execute code, ELSE set text to label... Unfortunately even when checkbox is not checked, code below executes... Also when I check checkbox, ELSE statement does not turn off text "Box is not checked"...
@void MainWindow::checkbox()
{
if (ui->checkBox->isChecked())
{ui->Play->setEnabled(false); if (QTime::currentTime(),(QTime::currentTime() > QTime(9,25,00)) & (QTime::currentTime()< QTime(9,55,00))) { player->play(); } else{ player->stop(); } } else { ui->label->setText("Box is not checked!"); }
}@
I am using timer for this as well....
@timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(checkbox()));
timer->start(1000);@ -
are you sure that the AND operator "&&" is written right?
-
I tried to use double & as well, but it's same... It should not even execute that part of the code as long as checkbox is not checked... But it simply execute everything even though checkbox is not checked...
-
Hi,
Your test doesn't do what you think it does. Have a look "here":http://www.cplusplus.com/doc/tutorial/operators/ about using the comma operator (which in your case has nothing to do here). And you are not using the logical and operator but the bitwise which are not the same thing.
You should rather have something like:
@
QTime current = QTimer::currentTime();
if ((current > QTime(9,25,00)) && (current < QTime(9,55,00)))
@ -
Eww... Missed that part :D Anyways it has exactly the same result... I just realised I posted something that is not problem here ... So tired that I forgot what I actually want...
Well, I will try to explain... I have a media player and I have two checkboxes as you can see on image... So if one checkbox is checked and time matches start playing a song... That part works well...
But problem is if both checkboxes are checked... Then none of them will play... checkbox () supposed to start at 9:25 - 9:55 but second one (checkbox1())is executing code player->stop()... So my question is how to make checkbox1() stop executing ELSE statement (player -> stop) when checkbox() is executing and vice versa....
-
Solved with else if statement...