Hello Guy,
I trying to put a while(1) C function in my Qt project.
I want to run it in the background of a specific Gui.
I have been trying to use threads to do it .I tried declaring the thread in main() and my Gui cpp file(infuison.cpp) But there seem to be a problem.
this is what i have done.
QThread: Destroyed while thread is still running
ASSERT failure in QThread::setTerminationEnabled(): "Current thread was not started with QThread.", file thread\qthread_win.cpp, line 574
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
//threading.h
#ifndef THREADINGS_H
#define THREADINGS_H
#include <QObject>
#include <QThread>
{
Q_OBJECT
public:
explicit Threadings
(QObject *parent
= 0);
signals:
public slots:
void runAlgoMain();
};
#endif // THREADINGS_H
//threading.h
#ifndef THREADINGS_H
#define THREADINGS_H
#include <QObject>
#include <QThread>
class Threadings : public QObject
{
Q_OBJECT
public:
explicit Threadings(QObject *parent = 0);
void DoSetup(QThread &cThread);
signals:
public slots:
void runAlgoMain();
};
#endif // THREADINGS_H
To copy to clipboard, switch view to plain text mode
//threadings.cpp
#include "threadings.h"
extern "C++"
{
#include "test.h"
}
Threadings
::Threadings(QObject *parent
) :{
}
void Threadings
::DoSetup(QThread &cThread
) {
connect(&cThread,SIGNAL(started()),this,SLOT(runAlgoMain()));
}
void Threadings::runAlgoMain()
{
runAlgoMain();
}
//threadings.cpp
#include "threadings.h"
extern "C++"
{
#include "test.h"
}
Threadings::Threadings(QObject *parent) :
QObject(parent)
{
}
void Threadings::DoSetup(QThread &cThread)
{
connect(&cThread,SIGNAL(started()),this,SLOT(runAlgoMain()));
}
void Threadings::runAlgoMain()
{
runAlgoMain();
}
To copy to clipboard, switch view to plain text mode
#include infusion.cpp
#include "threadings.h"
Infusion
::Infusion(QWidget *parent
) : ui(new Ui::Infusion)
{
Threadings cThreadings;
cThreadings.DoSetup(cThread);
cThreadings.moveToThread(&cThread);
cThread.start();
}
#include infusion.cpp
#include "threadings.h"
Infusion::Infusion(QWidget *parent) :
QWidget(parent),
ui(new Ui::Infusion)
{
QThread cThread;
Threadings cThreadings;
cThreadings.DoSetup(cThread);
cThreadings.moveToThread(&cThread);
cThread.start();
}
To copy to clipboard, switch view to plain text mode
Am i doing threading right ? Please help
Bookmarks