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