Running Threads Simultanously using Qt
I have a problem. I have a Qiwidget which has 2 pushbuttons. On pressing one button i need to play back 1 file using some playback technique. On clicking the other button I want to playback another file. I made the classes using the playback's for the 2 files as threads. But when i try to push the 1st button my application gets stuck and i am not able to press the second button. It gets blocked till my playback is over.
I want to be able to use my main application irrespective of the files playing. How can i achieve that in Qt.
playback file 1.h..
class PlaySource1 : public QThread
{
public:
PlaySource1();
virtual void run();
};
playbackfile.cpp
PlaySource1::PlaySource1()
{
}
void PlaySource1开发者_如何学运维::run()
{
some code
}
now in my main file .cpp when i run the code like :
void Test::on_pbPlaySource1_clicked()
{
PlaySource1 *playSource1 = new PlaySource1;
playSource1->run();
}
my code gets blocked by the thread playback. But i dont want it to get blocked. Please help.
You should call
playSource1->start();
not run()
. See the "Starting a Thread" section in the Qt Starting Threads with QThread documentation.
精彩评论