Results 1 to 2 of 2

Thread: signal-slot problem with QVector

  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default signal-slot problem with QVector

    hi,
    im having a problem sending a vector trough signal-slot connection.
    here is my code:

    Qt Code:
    1. class frmMain : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. frmMain(QWidget *parent = 0, Qt::WFlags flags = 0);
    7. ~frmMain();
    8.  
    9. sphThread* SPHthread;
    10.  
    11. public slots:
    12. void startSimulation(void);
    13. void addLog(QString _LogText);
    14. void drawPlot(CPlotPoint* _Point);
    15. void drawPlots(QVector<CPlotPoint*> _Point);
    16.  
    17.  
    18. private:
    19. Ui::frmMainClass ui;
    20. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void frmMain::startSimulation(void)
    2. {
    3. SPHthread=new sphThread(this);
    4. connect(
    5. SPHthread,
    6. SIGNAL(refreshLog(QString)),
    7. this,
    8. SLOT(addLog(QString)));
    9. connect(
    10. SPHthread,
    11. SIGNAL(refreshPlot(CPlotPoint*)),
    12. this,
    13. SLOT(drawPlot(CPlotPoint*)));
    14. connect(
    15. SPHthread,
    16. SIGNAL(refreshPlots(QVector<CPlotPoint*>)),
    17. this,
    18. SLOT(drawPlots(QVector<CPlotPoint*>)));
    19. SPHthread->start();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class sphThread : public QThread
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. sphThread(QObject *parent);
    7. ~sphThread();
    8.  
    9. void run();
    10.  
    11. signals:
    12. void refreshLog(QString _LogText);
    13. void refreshPlot(CPlotPoint* _Point);
    14. void refreshPlots(QVector<CPlotPoint*> _Point);
    15. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void sphThread::run(void)
    2. {
    3. CPlotPoint* _Point=new CPlotPoint;
    4. QVector<CPlotPoint*> _VectorPoints;
    5. for (qint32 i=0;i<100;i++)
    6. {
    7. for (qint32 j=0;j<10;j++)
    8. {
    9. emit refreshPlot(_Point);
    10. emit refreshPlots(_VectorPoints);
    11. emit refreshLog("*");
    12. }
    13. QThread::sleep(1);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    for testing i append different characters to text log:
    Qt Code:
    1. void frmMain::addLog(QString _LogText)
    2. {
    3. ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"*");
    4. }
    5. void frmMain::drawPlot(CPlotPoint* _Point)
    6. {
    7. ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"+");
    8. }
    9. void frmMain::drawPlots(QVector<CPlotPoint*> _Point)
    10. {
    11. ui.txtLog->setPlainText(ui.txtLog->toPlainText()+"-");
    12. }
    To copy to clipboard, switch view to plain text mode 
    but result is:
    Qt Code:
    1. +*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+..
    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: signal-slot problem with QVector

    To use the type T in queued signal and slot connections, qRegisterMetaType<T>() must be called before the first connection is established. See qRegisterMetaType() docs for more details.
    J-P Nurmi

Similar Threads

  1. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  2. problem with slot
    By as001622 in forum Qt Programming
    Replies: 4
    Last Post: 24th May 2008, 08:02
  3. Problem with qvector
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2008, 01:02
  4. Problem with slot
    By beerkg in forum Qt Programming
    Replies: 29
    Last Post: 3rd April 2007, 19:54

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.