[SOLVED] QThread cannot queue arguments of type 'QVector<quint8>'
-
Hey!
I am building an application to read one 64bit buffer per millisecond from my HID-device.
The problem is, that it takes Qt 8ms to poll the device, which means I am losing valuable data in the time between.
I am thinking, that moving time critical functions to a separate thread might help, and this is the way I am trying to do it:@
// HidDevice class
class HidDevice : public QObject
{
Q_OBJECT
// ...
signals:
void newDataReady(QVector<quint8> buffer_in);
// ...
}// MainWindow class
class MainWindow : public QMainWindow
{
Q_OBJECT
// ...
public slots:
void parseReportIn(QVector<quint8> buffer_in);private:
HidDevice *myDevice;
QTimer *usbPollTimer;
QThread *t;
// ...
}// MainWindow constructor
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// ...
myDevice = new HidDevice;
usbPollTimer = new QTimer;
// Connect timer to USB-poll-method
connect(usbPollTimer,SIGNAL(timeout()),myDevice,SLOT(pollDevice()));
// Connect polled-results to parser-method
connect(myDevice,SIGNAL(newDataReady(QVector<quint8>)),this,SLOT(parseReportIn(QVector<quint8>)));
// Check USB-Endpoint as often as possible
usbPollTimer->start(0);
// USB-polling should happen in this thread
t = new QThread;
// Move time critical USB objects to t
myDevice->moveToThread(t);
usbPollTimer->moveToThread(t);
// Run the thread
t->start();
// ...
}
@Running this code results in:
@
QObject::connect: Cannot queue arguments of type 'QVector<quint8>'
(Make sure 'QVector<quint8>' is registered using qRegisterMetaType().)
@I have found solutions to slightly different problems, (like "this one":http://qt-project.org/forums/viewthread/2884) but was not able to adapt them into my code.
Can anybody tell me the correct syntax to typedef my QVector that will actually work?
Thank you!
schmaunz
-
Hi,
Like the error message says, you need to register the type first. Call this before you make your connection:
@
qRegisterMetaType< QVector<quint8> >("QVector<quint8>");
@ -
Allright, thank you!
I thought I had to choose an alias for QVector<quint8> and got totally confused.
But your line of code before my connect totally did the trick, if you remember to put spaces between the angled brackets :)
Sadly that didn't solve my problem :(
I am still losing 8ms on each poll and it doesn't make sense to me, but I rather open a new thread since that's a completely different issue.Thanks again!
schmaunz