Ok, that clarified some things. I'm still having a little issue. My classes look as follows:
class InventoryThread
: public QObject{
Q_OBJECT
private:
int handle;
RFID_18K6C_INVENTORY_PARMS * inventoryParms;
RFID_18K6C_INVENTORY_PARMS * SetInventoryParams(const RFID_RADIO_HANDLE handle, const int cycles);
public:
signals:
public slots:
void DoInventory();
};
{
handle = h;
list = lst;
list->connect(timer,SIGNAL(timeout()),SLOT(clear()));
//connect(timer,SIGNAL(timeout()),list,SLOT(clear()));
timer->setSingleShot(false);
timer->start(1500);
}
void InventoryThread::DoInventory()
{
printf("Doing inventory\n");
RFID_18K6C_INVENTORY_PARMS * parms = SetInventoryParams(handle, 5);
printf("Tag Inventory returned %d\n", RFID_18K6CTagInventory(handle, parms, 0));
free(parms);
}
class InventoryThread : public QObject
{
Q_OBJECT
private:
int handle;
QListWidget * list;
RFID_18K6C_INVENTORY_PARMS * inventoryParms;
RFID_18K6C_INVENTORY_PARMS * SetInventoryParams(const RFID_RADIO_HANDLE handle, const int cycles);
QTimer * timer;
public:
explicit InventoryThread(QObject *parent = 0, int h = 0, QListWidget *lst = 0);
signals:
public slots:
void DoInventory();
};
InventoryThread::InventoryThread(QObject *parent, int h, QListWidget * lst) : QObject(parent)
{
handle = h;
list = lst;
timer = new QTimer(this);
list->connect(timer,SIGNAL(timeout()),SLOT(clear()));
//connect(timer,SIGNAL(timeout()),list,SLOT(clear()));
timer->setSingleShot(false);
timer->start(1500);
}
void InventoryThread::DoInventory()
{
printf("Doing inventory\n");
RFID_18K6C_INVENTORY_PARMS * parms = SetInventoryParams(handle, 5);
printf("Tag Inventory returned %d\n", RFID_18K6CTagInventory(handle, parms, 0));
free(parms);
}
To copy to clipboard, switch view to plain text mode
In my main class I have
{
protected:
void run() { exec(); }
};
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(this
->ui
->start,
SIGNAL(clicked
()),
this,
SLOT(StartInventory
()));
invThread = new InventoryThread(0, handle, this->ui->listWidget);
thr = new QThreadEx();
invThread->moveToThread(thr);
invThread->connect(thr,SIGNAL(started()),SLOT(DoInventory()));
}
class QThreadEx : public QThread
{
protected:
void run() { exec(); }
};
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(this->ui->start,SIGNAL(clicked()),this,SLOT(StartInventory()));
invThread = new InventoryThread(0, handle, this->ui->listWidget);
thr = new QThreadEx();
invThread->moveToThread(thr);
invThread->connect(thr,SIGNAL(started()),SLOT(DoInventory()));
}
To copy to clipboard, switch view to plain text mode
Finally, when I click on my start button I call thr->start() and when I click on the end button I call thr->quit(). This scheme works only for the first time. If I click on the start button again the thread will not launch (I can't see the printf's output on my terminal). Obviously I'm still missing something. How can I launch again my thread after quitting it (or after DoInventory() slot ended its work)?
Bookmarks