hi,
im having a problem sending a vector trough signal-slot connection.
here is my code:
{
Q_OBJECT
public:
frmMain
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~frmMain();
sphThread* SPHthread;
public slots:
void startSimulation(void);
void drawPlot(CPlotPoint* _Point);
void drawPlots(QVector<CPlotPoint*> _Point);
private:
Ui::frmMainClass ui;
};
class frmMain : public QMainWindow
{
Q_OBJECT
public:
frmMain(QWidget *parent = 0, Qt::WFlags flags = 0);
~frmMain();
sphThread* SPHthread;
public slots:
void startSimulation(void);
void addLog(QString _LogText);
void drawPlot(CPlotPoint* _Point);
void drawPlots(QVector<CPlotPoint*> _Point);
private:
Ui::frmMainClass ui;
};
To copy to clipboard, switch view to plain text mode
void frmMain::startSimulation(void)
{
SPHthread=new sphThread(this);
connect(
SPHthread,
this,
connect(
SPHthread,
SIGNAL(refreshPlot(CPlotPoint*)),
this,
SLOT(drawPlot(CPlotPoint*)));
connect(
SPHthread,
SIGNAL(refreshPlots(QVector<CPlotPoint*>)),
this,
SLOT(drawPlots(QVector<CPlotPoint*>)));
SPHthread->start();
}
void frmMain::startSimulation(void)
{
SPHthread=new sphThread(this);
connect(
SPHthread,
SIGNAL(refreshLog(QString)),
this,
SLOT(addLog(QString)));
connect(
SPHthread,
SIGNAL(refreshPlot(CPlotPoint*)),
this,
SLOT(drawPlot(CPlotPoint*)));
connect(
SPHthread,
SIGNAL(refreshPlots(QVector<CPlotPoint*>)),
this,
SLOT(drawPlots(QVector<CPlotPoint*>)));
SPHthread->start();
}
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
~sphThread();
void run();
signals:
void refreshPlot(CPlotPoint* _Point);
void refreshPlots(QVector<CPlotPoint*> _Point);
};
class sphThread : public QThread
{
Q_OBJECT
public:
sphThread(QObject *parent);
~sphThread();
void run();
signals:
void refreshLog(QString _LogText);
void refreshPlot(CPlotPoint* _Point);
void refreshPlots(QVector<CPlotPoint*> _Point);
};
To copy to clipboard, switch view to plain text mode
void sphThread::run(void)
{
CPlotPoint* _Point=new CPlotPoint;
QVector<CPlotPoint*> _VectorPoints;
for (qint32 i=0;i<100;i++)
{
for (qint32 j=0;j<10;j++)
{
emit refreshPlot(_Point);
emit refreshPlots(_VectorPoints);
emit refreshLog("*");
}
}
}
void sphThread::run(void)
{
CPlotPoint* _Point=new CPlotPoint;
QVector<CPlotPoint*> _VectorPoints;
for (qint32 i=0;i<100;i++)
{
for (qint32 j=0;j<10;j++)
{
emit refreshPlot(_Point);
emit refreshPlots(_VectorPoints);
emit refreshLog("*");
}
QThread::sleep(1);
}
}
To copy to clipboard, switch view to plain text mode
for testing i append different characters to text log:
void frmMain
::addLog(QString _LogText
) {
ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"*");
}
void frmMain::drawPlot(CPlotPoint* _Point)
{
ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"+");
}
void frmMain::drawPlots(QVector<CPlotPoint*> _Point)
{
ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"-");
}
void frmMain::addLog(QString _LogText)
{
ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"*");
}
void frmMain::drawPlot(CPlotPoint* _Point)
{
ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"+");
}
void frmMain::drawPlots(QVector<CPlotPoint*> _Point)
{
ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"-");
}
To copy to clipboard, switch view to plain text mode
but result is:
+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+..
+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+..
To copy to clipboard, switch view to plain text mode
so refreshPlots(QVector<CPlotPoint*> _Point); but signal drawPlots(QVector<CPlotPoint*> _Points) is never executed. Any idea? maybe the problem is something about QVector and signals?
Bookmarks