2

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.

Deb
  • 25
  • 5

1 Answers1

4

You should call

playSource1->start();

not run(). See the "Starting a Thread" section in the Qt Starting Threads with QThread documentation.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • It worked. But it again is creating some other problem. When i click another button for another playback, the previous playback stops. I dont want it to stop till i tell it to stop explicitly. I want it to continue playing till i manually tell it to stop playing.. – Deb Jun 23 '11 at 06:27
  • I have made two seperate threads for them. Thread1 and thread 2. So i want thread 2 to play while thread 1 is playing. How do i achieve that. – Deb Jun 23 '11 at 10:04