Hi, I'm developing a qt application that interfaces with an external hardware device. My application consists of just 2 start/stop buttons and a listwidget used to display data received from the device. Since the data acquisition from the device requires me to call a blocking function, I've decided to put the call in a separated thread because data acquisition can be stopped only by calling another function from another thread. So I've created this QThread subclass:
class InventoryThread
: public QThread{
Q_OBJECT
private:
int handle;
RFID_18K6C_INVENTORY_PARMS * inventoryParms;
RFID_18K6C_INVENTORY_PARMS * SetInventoryParams(const RFID_RADIO_HANDLE handle, const int cycles);
public:
explicit InventoryThread
(QObject *parent
= 0,
int h
= 0);
protected:
void run();
signals:
public slots:
};
class InventoryThread : public QThread
{
Q_OBJECT
private:
int handle;
RFID_18K6C_INVENTORY_PARMS * inventoryParms;
RFID_18K6C_INVENTORY_PARMS * SetInventoryParams(const RFID_RADIO_HANDLE handle, const int cycles);
public:
explicit InventoryThread(QObject *parent = 0, int h = 0);
protected:
void run();
signals:
public slots:
};
To copy to clipboard, switch view to plain text mode
The relevant implementation is this:
InventoryThread
::InventoryThread(QObject *parent,
int h
) :{
handle = h;
}
void InventoryThread::run()
{
RFID_18K6CTagInventory(handle, SetInventoryParams(handle, 5), 0);
}
InventoryThread::InventoryThread(QObject *parent, int h) :
QThread(parent)
{
handle = h;
}
void InventoryThread::run()
{
RFID_18K6CTagInventory(handle, SetInventoryParams(handle, 5), 0);
}
To copy to clipboard, switch view to plain text mode
The main window code will call InventoryThread::start() when I click on the start button, then RFID_18K6CTagInventory will be called (which is a blocking function). This function can be stopped only by calling RFID_RadioCancelOperation in the main thread. Now, I'm not sure if my approach is correct, the documentation about QThread its main loop il pretty confusing.
What should I do?
Bookmarks