Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// header file
class PlayerT : public QThread
{
Q_OBJECT
public:
void setup(some param);
void run();
QProcess *qp;
QString cmd;
public slots:
void stopped();
}
// cpp file
void PlayerT::setup(some param)
{
// some code
}
void PlayerT::run()
{
qDebug("THREAD: Waiting for 15 seconds to execute external APP...\n");
SleeperThread::Sleep(15000);
qp->execute(QString as command line);
// connect(qp, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(stopped())); //Add this line will cause error at runtime
}
void PlayerT::stopped()
{
qDebug("THREAD: External APP ended...\n");
}
|
This post has been edited 1 times, last edit by "RR_TW" (Apr 26th 2010, 12:33pm)
|
|
Source code |
1 2 |
qDebug("THREAD: Waiting for 15 seconds to execute external APP...\n");
SleeperThread::Sleep(15000);
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// header file
class PlayerT : public QThread
{
Q_OBJECT
public:
void setup(some param);
void run();
QProcess *qp;
QString cmd;
public slots:
void stopped();
}
// cpp file
void PlayerT::setup(QString param)
{
cmd.append(param);
}
void PlayerT::run()
{
qDebug("THREAD: Waiting for 15 seconds to execute external APP...\n");
SleeperThread::Sleep(15000);
qp->execute(cmd);
// connect(qp, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(stopped())); //Add this line will cause error at runtime
}
void PlayerT::stopped()
{
qDebug("THREAD: External APP ended...\n");
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#ifndef SLEEPERTHREAD_H
#define SLEEPERTHREAD_H
#include <QtCore/QThread>
class SleeperThread : public QThread
{
public:
static void Sleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};
#endif // SLEEPERTHREAD_H
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//header
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
PlayerT pT; //QThread to launch all players
};
//cpp
pT.setup("./xxxPlayer"); //An executable file on linux
pT.start();
|
|
|
Source code |
1 2 3 4 |
Starting /tftpboot/test_code/TestProject/TestProject... MSG: Start to run external application in 15 seconds... The program has unexpectedly finished. /tftpboot/test_code/TestProject/TestProject exited with code 0 |
|
|
Source code |
1 2 3 4 5 6 7 8 |
void PlayerT::run()
{
qDebug("MSG: Start to run external application in 15 seconds...");
SleeperThread::Sleep(15000);
qp=new QProcess(); // This line just added
qp->execute(cmd);
connect(qp, SIGNAL(finished(int)), this, SLOT(stopped()));
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 |
void PlayerT::run()
{
qDebug("MSG: Start to run external application in 15 seconds...");
//SleeperThread::Sleep(15000);
qp = new QProcess;
connect(qp, SIGNAL(finished(int)), this, SLOT(stopped()));
qp->start(cmd);
qp->waitForFinished();
} // the end of thread.
|