Results 1 to 10 of 10

Thread: Problem passing QVector containing QPointF through signal-slot

  1. #1
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Problem passing QVector containing QPointF through signal-slot

    Hello!

    I would like to know if someone know's how to pass a Qvector<QPointF> through signals & slots. I've been able to pass a QVector<int> through signals and slots but I'm unable to pass a vector containing QPointF. Could anyone tell me what I'm doing wrong? I will post some sample code below:

    main.cpp:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4. app.setPalette(Qt::darkGray);
    5.  
    6. qRegisterMetaType< QVector<int> >("QVector<int>");
    7.  
    8. MainWindow mainWindow;
    9.  
    10. SamplingThread samplingThread;
    11. samplingThread.setInterval(1000);
    12.  
    13. mainWindow.connect(&samplingThread, SIGNAL(sendSampleVector(QVector<int>)), &mainWindow, SLOT(plotSampleVector(QVector<int>)));
    14.  
    15. mainWindow.show();
    16.  
    17. samplingThread.start();
    18.  
    19. bool ok = app.exec();
    20.  
    21. samplingThread.stop();
    22. samplingThread.wait(1000);
    23.  
    24. return ok;
    25. }
    To copy to clipboard, switch view to plain text mode 

    samplingthread.cpp (in samplingthread.h the signal is defined as: void sendSampleVector(QVector<int>))
    Qt Code:
    1. #include "samplingthread.h"
    2. #include <QVector>
    3.  
    4. SamplingThread::SamplingThread( QObject *parent ):
    5. QwtSamplingThread( parent )
    6. {
    7. }
    8.  
    9. void SamplingThread::sample(double elapsed)
    10. {
    11. QVector<int> sampleVector;
    12. sampleVector.append(1);
    13. sampleVector.append(2);
    14. sampleVector.append(3);
    15.  
    16. emit sendSampleVector(sampleVector);
    17. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp (in mainwindow.cpp the slot is defined as void plotSampleVector(QVector<int>))
    Qt Code:
    1. void MainWindow::plotSampleVector(QVector<int> sampleVector)
    2. {
    3. qDebug()<<sampleVector;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Now, the code above works but when I swap the int to QPointf I get tons of errors and it doesn't work. What am I not understanding in this case?

    Also, when using QPointF my samplingthread.cpp is:
    Qt Code:
    1. void SamplingThread::sample(double elapsed)
    2. {
    3. QVector<QPointF> sampleVector;
    4. sampleVector.append(QPointF(1.0,1.0));
    5. sampleVector.append(QPointF(2.0,2.0));
    6. sampleVector.append(QPointF(3.0,3.0));
    7.  
    8. emit sendSampleVector(sampleVector);
    9. }
    To copy to clipboard, switch view to plain text mode 

    All help apreciated, thanks!

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem passing QVector containing QPointF through signal-slot

    I get tons of errors and it doesn't work
    Posting them here could be a good idea.
    btw
    when I swap the int to QPointf
    Did you swap them in signal / slot definition and connect statements too ?

  3. #3
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Quote Originally Posted by stampede View Post
    Posting them here could be a good idea.
    btw
    Here is my compile output:
    compileoutput.txt

    Quote Originally Posted by stampede View Post
    Did you swap them in signal / slot definition and connect statements too ?
    Yes I did.

    Signal definition: void sendSampleVector(QVector<QPointF>)
    Slot definition: void plotSampleVector(QVector<QPointF>)
    connect: mainWindow.connect(&samplingThread, SIGNAL(sendSampleVector(QVector<QPointF>)), &mainWindow, SLOT(plotSampleVector(QVector<QPointF>)))

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem passing QVector containing QPointF through signal-slot

    The first error seems to be a missing #include <QPointF> statement.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Quote Originally Posted by wysota View Post
    The first error seems to be a missing #include <QPointF> statement.
    Right, I missed that but I still get a bunch of errors. Below is the new compile output. (had to zip it because textfile was to large)
    compileoutput2.txt.zip

    Or does anyone know a better way to pass a number of points from one thread to another?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Still seems to be a missing include in samplingthread.h.

    I can tell you in aedvance that once you solve these problems you will have to use qRegisterMetaType.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Quote Originally Posted by wysota View Post
    Still seems to be a missing include in samplingthread.h.

    I can tell you in aedvance that once you solve these problems you will have to use qRegisterMetaType.
    Do you have any idea on what's missing? Because before when I forgot the includes I got errors in my own files but now they are somewhere else. And aren't I already using qRegisterMetaType (in the first post in main.cpp)?

    Also, a more general question so I dont waste time on this problem if it's a bad/inefficient solution; do I have the right approach to what I'm trying to achieve?

    What I'm doing is that I want to have a worker thread reading sensor data and at some times I want to append some of the collected samples to a plot. Would it be better to use sared memory or something between the two threads? Seems harder though...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Quote Originally Posted by Mindstormer View Post
    Do you have any idea on what's missing?
    Based on the first error posted, seems a missing #include <QPointF>

    And aren't I already using qRegisterMetaType (in the first post in main.cpp)?
    You are using it for QVector<int> and not QVector<QPointF>.

    Also, a more general question so I dont waste time on this problem if it's a bad/inefficient solution; do I have the right approach to what I'm trying to achieve?
    Well... it depends what you want to achieve. Most probably you can replace the thread with a timer. Of course this won't cause your missing include problem to disappear
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    Mindstormer (27th March 2014)

  10. #9
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Quote Originally Posted by wysota View Post
    Based on the first error posted, seems a missing #include <QPointF>
    Finally was able to solve the problem! It turns out that I was looking in the wrong file, I had QpointF included in my samplingthread.cpp but I had forgot to include it in my samplingthread.h file!

    You know why I had to include QpointF when Qvector in the header file? I'm just curious... :P

    Quote Originally Posted by wysota View Post
    You are using it for QVector<int> and not QVector<QPointF>.
    I was using QVector<QPointF> in the registermetatype but the error was in the header file as I just discovered.

    Thanks for all the help guys, problem solved and I'm happy to move on!

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem passing QVector containing QPointF through signal-slot

    Quote Originally Posted by Mindstormer View Post
    You know why I had to include QpointF when Qvector in the header file? I'm just curious... :P
    Because you had a declaration of a QVector<QPointF> object in the header file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 5
    Last Post: 2nd September 2011, 23:11
  2. Passing data via signal/slot
    By gib in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2010, 05:49
  3. Problem with passing Pointers to a Slot
    By Basti300 in forum Newbie
    Replies: 2
    Last Post: 26th May 2010, 14:45
  4. signal-slot problem with QVector
    By stefan in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 13:58
  5. Passing a pointer in Signal/Slot Connection
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 6th November 2007, 19:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.