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:
int main(int argc, char *argv[])
{
app.setPalette(Qt::darkGray);
qRegisterMetaType< QVector<int> >("QVector<int>");
MainWindow mainWindow;
SamplingThread samplingThread;
samplingThread.setInterval(1000);
mainWindow.connect(&samplingThread, SIGNAL(sendSampleVector(QVector<int>)), &mainWindow, SLOT(plotSampleVector(QVector<int>)));
mainWindow.show();
samplingThread.start();
bool ok = app.exec();
samplingThread.stop();
samplingThread.wait(1000);
return ok;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setPalette(Qt::darkGray);
qRegisterMetaType< QVector<int> >("QVector<int>");
MainWindow mainWindow;
SamplingThread samplingThread;
samplingThread.setInterval(1000);
mainWindow.connect(&samplingThread, SIGNAL(sendSampleVector(QVector<int>)), &mainWindow, SLOT(plotSampleVector(QVector<int>)));
mainWindow.show();
samplingThread.start();
bool ok = app.exec();
samplingThread.stop();
samplingThread.wait(1000);
return ok;
}
To copy to clipboard, switch view to plain text mode
samplingthread.cpp (in samplingthread.h the signal is defined as: void sendSampleVector(QVector<int>))
#include "samplingthread.h"
#include <QVector>
SamplingThread
::SamplingThread( QObject *parent
): QwtSamplingThread( parent )
{
}
void SamplingThread::sample(double elapsed)
{
QVector<int> sampleVector;
sampleVector.append(1);
sampleVector.append(2);
sampleVector.append(3);
emit sendSampleVector(sampleVector);
}
#include "samplingthread.h"
#include <QVector>
SamplingThread::SamplingThread( QObject *parent ):
QwtSamplingThread( parent )
{
}
void SamplingThread::sample(double elapsed)
{
QVector<int> sampleVector;
sampleVector.append(1);
sampleVector.append(2);
sampleVector.append(3);
emit sendSampleVector(sampleVector);
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp (in mainwindow.cpp the slot is defined as void plotSampleVector(QVector<int>))
void MainWindow::plotSampleVector(QVector<int> sampleVector)
{
qDebug()<<sampleVector;
}
void MainWindow::plotSampleVector(QVector<int> sampleVector)
{
qDebug()<<sampleVector;
}
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:
void SamplingThread::sample(double elapsed)
{
QVector<QPointF> sampleVector;
sampleVector.
append(QPointF(1.0,
1.0));
sampleVector.
append(QPointF(2.0,
2.0));
sampleVector.
append(QPointF(3.0,
3.0));
emit sendSampleVector(sampleVector);
}
void SamplingThread::sample(double elapsed)
{
QVector<QPointF> sampleVector;
sampleVector.append(QPointF(1.0,1.0));
sampleVector.append(QPointF(2.0,2.0));
sampleVector.append(QPointF(3.0,3.0));
emit sendSampleVector(sampleVector);
}
To copy to clipboard, switch view to plain text mode
All help apreciated, thanks!
Bookmarks