PDA

View Full Version : Problem with a custom slot of a qlabel



nomwise
27th February 2012, 11:13
Hi!

I have a problem with a custom slot of a QLabel. The error that the compiler gives is:

Object::connect: No such slot QLabel::displayIzquierda(int)
Object::connect: (receiver name: 'izquierda')

It is the first time that I have a slot and i don't know where the error may be.

Thanks in advance!!!

trasera.h



#ifndef TRASERA_H
#define TRASERA_H
#include <QtGui>
#include "ui_trasera.h"
#include "../include/prueba/ultrasonidos.h"

class Ultrasonidos;

class Trasera : public QWidget
{
Q_OBJECT

public:
explicit Trasera(const QString &title, const QString &content, const QString &imagePath, QWidget *parent = 0);

Ui::trasera ui;

Ultrasonidos *ultra;
void inicializarInterfazUltrasonidos();

public slots:
void displayIzquierda (int i);
};

#endif // TRASERA_H



trasera.cpp



#include "../include/prueba/trasera.h"
#include "../build/ui_trasera.h"
#include <QtGui>
#include <qt4/QtCore/qnamespace.h>

Trasera::Trasera(const QString &title, const QString &content, const QString &imagePath, QWidget *parent) :
QWidget(parent)
{
ui.setupUi(this);
ultra = new Ultrasonidos();
inicializarInterfazUltrasonidos();
}

void Trasera::inicializarInterfazUltrasonidos()
{
connect(ultra, SIGNAL(datoIzquierda(int)), ui.izquierda, SLOT(displayIzquierda(int))); <---------- FAIL //NOTE: ui.izquierda is a Qlabel
}

void Trasera::displayIzquierda(int i) {
switch(i) {
case 0:
ui.izquierda->setPixmap(QPixmap(QString::fromUtf8(":/images/verde")));
break;
case 1:
ui.izquierda->setPixmap(QPixmap(QString::fromUtf8(":/images/amarillo")));
break;
}
}



Ultrasonidos.h



class Ultrasonidos : public QThread
{
Q_OBJECT

public:
Ultrasonidos();

signals:

void datoIzquierda(int i);

};

mentalmushroom
27th February 2012, 11:27
QLabel doesn't have a slot displayIzquierda(int)

nomwise
27th February 2012, 11:43
But... do i create a custom slot of a Qlabel?

mentalmushroom
27th February 2012, 11:47
No, but you connect a signal to it.



connect(ultra, SIGNAL(datoIzquierda(int)), ui.izquierda, SLOT(displayIzquierda(int))); <---------- FAIL //NOTE: ui.izquierda is a Qlabel

nomwise
27th February 2012, 12:07
No, but you connect a signal to it.

I have replaced SLOT(displayIzquierda(int)) by SLOT(setNum(int) and work:

when datoIzquierda = 1 --> ui.izquierda = 1
when datoIzquierda = 2 --> ui.izquierda = 2
....

But .. i want to do is: when datoIzquierda = 1, ui.izquierda->setPixmap( "THE IMAGE 1" );
when datoIzquierda = 2, ui.izquierda->setPixmap( "THE IMAGE 2" );
...

How can do this?

thanks!

mentalmushroom
27th February 2012, 12:19
connect the signal to the slot of your class, not qlabel

nomwise
27th February 2012, 12:26
Thanks!!!!!! Now it works!

The solution is: connect(ultra, SIGNAL(datoIzquierda(int)), this, SLOT(displayIzquierda(int)));