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? 
#ifndef EMISOR_H
#define EMISOR_H
#include <QThread>
{
Q_OBJECT
public:
Emisor();
void llamar();
virtual void run(); // if I comment this (and its implementation), it works
signals:
void enviar();
};
#endif // EMISOR_H
//emisor.cpp
#include "emisor.h"
Emisor::Emisor()
{
}
void Emisor::llamar(){
emit enviar();
}
//................
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void recibir();
};
#endif // MAINWINDOW_H
//-----
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <emisor.h>
#include <stdio.h>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
Emisor e;
connect(&e,SIGNAL(enviar()),this,SLOT(recibir()));
e.llamar();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::recibir(){
printf("Hi");
}
#ifndef EMISOR_H
#define EMISOR_H
#include <QThread>
class Emisor : public QThread
{
Q_OBJECT
public:
Emisor();
void llamar();
virtual void run(); // if I comment this (and its implementation), it works
signals:
void enviar();
};
#endif // EMISOR_H
//emisor.cpp
#include "emisor.h"
Emisor::Emisor()
{
}
void Emisor::llamar(){
emit enviar();
}
//................
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void recibir();
};
#endif // MAINWINDOW_H
//-----
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <emisor.h>
#include <stdio.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Emisor e;
connect(&e,SIGNAL(enviar()),this,SLOT(recibir()));
e.llamar();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::recibir(){
printf("Hi");
}
To copy to clipboard, switch view to plain text mode
PD: sorry for my English
Bookmarks