Important: Please read the Qt Code of Conduct -

[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
    // ...
    void newDataReady(QVector<quint8> buffer_in);
    // ...

    // MainWindow class
    class MainWindow : public QMainWindow
    // ...
    public slots:
    void parseReportIn(QVector<quint8> buffer_in);

    HidDevice *myDevice;
    QTimer *usbPollTimer;
    QThread *t;
    // ...

    // MainWindow constructor
    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    // ...
    myDevice = new HidDevice;
    usbPollTimer = new QTimer;
    // Connect timer to USB-poll-method
    // Connect polled-results to parser-method
    // Check USB-Endpoint as often as possible
    // USB-polling should happen in this thread
    t = new QThread;
    // Move time critical USB objects to t
    // Run the thread
    // ...

    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": 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!


  • Moderators


    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!


Log in to reply