Re: Button-Controlled Loop
Once you start the loop, the Gui isn't accessible so you couldn't stop the loop. Two solutions: use QCoreApplication::processEvents() or use a thread for the loop. You also can read this article.
Re: Button-Controlled Loop
I was working on some other things I left out this part of my program. Anyway, I'm not familiar with the processEvents() can you help me out in a little more detail? Where and how do I implement this? I ended up with this--a lot of errors in my looper.cpp:(
Code:
#include <QtGui>
#include "looper.h"
bool stop;
void mainLoop();
basicLoop
::basicLoop(QWidget *parent
){
setupUi(this); // this sets up GUI
connect( startButton, SIGNAL( clicked() ), this, SLOT( startLoop() ) );
connect( stopButton, SIGNAL( clicked() ), this, SLOT( stopLoop() ) );
}
void basicLoop::startLoop()
{
&stop = false;
mainLoop();
}
void basicLoop::stopLoop()
{
&stop = true;
}
void mainLoop()
{
int i=0;
//check for stop button press
if (stopButton->isChecked) stopLoop();
while(!&stop)
{
textEdit
->append
(QString::number(i
));
i++;
}
}
I'm not sure if this is making sense..I don't know how to connect my stopButton now and how I would call the function stopLoop..
Re: Button-Controlled Loop
this is how its done.
Code:
void mainLoop()
{
int i=0;
//check for stop button press
//QCoreApplication::processEvents();//Put this inside loop
//if (stopButton->isChecked) stopLoop();//no need for this
while(!&stop)
{
textEdit
->append
(QString::number(i
));
i++;
}
}
Re: Button-Controlled Loop
thanks for that..I'm gettin close:)
just a minor problem here though..I couldn't access the textEdit object since my function mainLoop is not part of the widget basicLoop..how do I access to textEdit?
Re: Button-Controlled Loop
make a static function in your class which will return the textedit pointer.
btw, this question belongs to the newbie/C++ section