PDA

View Full Version : Problem with Signal and Slots and QThread



Informatix
4th June 2010, 21:53
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? :crying:


#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");

}









PD: sorry for my English

squidge
4th June 2010, 22:06
Wheres the implementation for run?

Tio
7th June 2010, 14:21
agreed, we need the run() function friend