You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, February 27th 2012, 11:22am

Problem with a custom slot of a qlabel

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

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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

Source code

1
2
3
4
5
6
7
8
9
10
11
12
class Ultrasonidos : public QThread 
{
   	Q_OBJECT
  
public:
	Ultrasonidos();
	
signals:
  
	void datoIzquierda(int i);
		
};

2

Monday, February 27th 2012, 1:18pm

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

3

Monday, February 27th 2012, 1:24pm

Trasera has that slot, not ui.izquierda.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.