Just trying out this class for the first time. I copied and pasted the example as a starting point, which contains the line
if (m.runThread())
but I think it is supposed to be
if (m.startThread())
Just trying out this class for the first time. I copied and pasted the example as a starting point, which contains the line
if (m.runThread())
but I think it is supposed to be
if (m.startThread())
I’ve just taken a quick look, I think that example is based on using a modal loop which is now strongly discouraged! I think it could probably change to something like this (untested).
class MyTask : private ThreadWithProgressWindow
{
public:
MyTask() : ThreadWithProgressWindow ("busy...", true, true)
{
launchTread();
}
~MyTask() override
{
stopThread (1000);
}
private:
void run() override
{
for (int i = 0; i < thingsToDo; ++i)
{
// must check this as often as possible, because this is
// how we know if the user's pressed 'cancel'
if (threadShouldExit())
break;
// this will update the progress bar on the dialog box
setProgress (i / (double) thingsToDo);
// ... do the business here...
}
}
void threadComplete (bool userPressedCancel) override
{
if (userPressedCancel)
{
// user pressed the cancel button..
}
else
{
// thread finished normally..
}
}
};
class ParentClass
{
public:
void doTheTask() { task = std::make_unique<MyTask>(); }
private:
std::unique_ptr<MyTask> task
};
Thanks, Anthony! Got busy with my day job, but I’ll try it out when I can!