Results 1 to 3 of 3

Thread: Problem with Signal and Slots and QThread

  1. #1
    Join Date
    Oct 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Problem with Signal and Slots and QThread

    Hi everyone,
    I have a trouble when I try to use signal and slots with QThread, when I write "void run();" in the Emisor's header and I implement it in the .cpp, the compilator says " :-1: error: collect2: ld returned 1 exit status" but if I omit these lines, It works. :S . I need to make my own run(), but I don't know why my program doesn't work.
    Can anybody help me?

    Qt Code:
    1. #ifndef EMISOR_H
    2. #define EMISOR_H
    3.  
    4. #include <QThread>
    5.  
    6.  
    7. class Emisor : public QThread
    8. {
    9. Q_OBJECT
    10. public:
    11. Emisor();
    12. void llamar();
    13. virtual void run(); // if I comment this (and its implementation), it works
    14.  
    15.  
    16. signals:
    17. void enviar();
    18. };
    19.  
    20. #endif // EMISOR_H
    21.  
    22. //emisor.cpp
    23.  
    24. #include "emisor.h"
    25.  
    26. Emisor::Emisor()
    27. {
    28. }
    29.  
    30. void Emisor::llamar(){
    31. emit enviar();
    32. }
    33.  
    34. //................
    35.  
    36. #ifndef MAINWINDOW_H
    37. #define MAINWINDOW_H
    38.  
    39. #include <QMainWindow>
    40.  
    41. namespace Ui {
    42. class MainWindow;
    43. }
    44.  
    45. class MainWindow : public QMainWindow {
    46. Q_OBJECT
    47. public:
    48. MainWindow(QWidget *parent = 0);
    49. ~MainWindow();
    50.  
    51. private:
    52. Ui::MainWindow *ui;
    53. public slots:
    54. void recibir();
    55. };
    56.  
    57. #endif // MAINWINDOW_H
    58.  
    59. //-----
    60.  
    61. #include "mainwindow.h"
    62. #include "ui_mainwindow.h"
    63. #include <emisor.h>
    64. #include <stdio.h>
    65.  
    66. MainWindow::MainWindow(QWidget *parent) :
    67. QMainWindow(parent),
    68. ui(new Ui::MainWindow)
    69. {
    70. ui->setupUi(this);
    71. Emisor e;
    72. connect(&e,SIGNAL(enviar()),this,SLOT(recibir()));
    73.  
    74. e.llamar();
    75.  
    76. }
    77.  
    78. MainWindow::~MainWindow()
    79. {
    80. delete ui;
    81.  
    82.  
    83. }
    84.  
    85. void MainWindow::recibir(){
    86. printf("Hi");
    87.  
    88. }
    To copy to clipboard, switch view to plain text mode 





    PD: sorry for my English

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Signal and Slots and QThread

    Wheres the implementation for run?

  3. #3
    Join Date
    Apr 2010
    Posts
    20
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with Signal and Slots and QThread

    agreed, we need the run() function friend

Similar Threads

  1. QThread signal and slots problem
    By mero in forum Qt Programming
    Replies: 8
    Last Post: 8th May 2010, 01:56
  2. Queuing problem with signal and slots
    By montylee in forum Qt Programming
    Replies: 4
    Last Post: 20th November 2009, 06:11
  3. QThread communication without signal and slots
    By forrestfsu in forum Qt Programming
    Replies: 16
    Last Post: 22nd May 2007, 00:43
  4. Signal-slots connection problem.
    By impeteperry in forum Qt Tools
    Replies: 26
    Last Post: 23rd January 2007, 14:33
  5. Problem with Signal and Slots
    By Kapil in forum Installation and Deployment
    Replies: 2
    Last Post: 10th February 2006, 08:51

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.