Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QThread cannot queue arguments of type 'QVector<quint8>'
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QThread cannot queue arguments of type 'QVector<quint8>'

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr.Floppy
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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>");
      @

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr.Floppy
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved