Results 1 to 7 of 7

Thread: Problem with a custom slot of a qlabel

  1. #1

    Default 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
    Qt Code:
    1. #ifndef TRASERA_H
    2. #define TRASERA_H
    3. #include <QtGui>
    4. #include "ui_trasera.h"
    5. #include "../include/prueba/ultrasonidos.h"
    6.  
    7. class Ultrasonidos;
    8.  
    9. class Trasera : public QWidget
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. explicit Trasera(const QString &title, const QString &content, const QString &imagePath, QWidget *parent = 0);
    15.  
    16. Ui::trasera ui;
    17.  
    18. Ultrasonidos *ultra;
    19. void inicializarInterfazUltrasonidos();
    20.  
    21. public slots:
    22. void displayIzquierda (int i);
    23. };
    24.  
    25. #endif // TRASERA_H
    To copy to clipboard, switch view to plain text mode 


    trasera.cpp
    Qt Code:
    1. #include "../include/prueba/trasera.h"
    2. #include "../build/ui_trasera.h"
    3. #include <QtGui>
    4. #include <qt4/QtCore/qnamespace.h>
    5.  
    6. Trasera::Trasera(const QString &title, const QString &content, const QString &imagePath, QWidget *parent) :
    7. QWidget(parent)
    8. {
    9. ui.setupUi(this);
    10. ultra = new Ultrasonidos();
    11. inicializarInterfazUltrasonidos();
    12. }
    13.  
    14. void Trasera::inicializarInterfazUltrasonidos()
    15. {
    16. connect(ultra, SIGNAL(datoIzquierda(int)), ui.izquierda, SLOT(displayIzquierda(int))); <---------- FAIL //NOTE: ui.izquierda is a Qlabel
    17. }
    18.  
    19. void Trasera::displayIzquierda(int i) {
    20. switch(i) {
    21. case 0:
    22. ui.izquierda->setPixmap(QPixmap(QString::fromUtf8(":/images/verde")));
    23. break;
    24. case 1:
    25. ui.izquierda->setPixmap(QPixmap(QString::fromUtf8(":/images/amarillo")));
    26. break;
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 


    Ultrasonidos.h
    Qt Code:
    1. class Ultrasonidos : public QThread
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Ultrasonidos();
    7.  
    8. signals:
    9.  
    10. void datoIzquierda(int i);
    11.  
    12. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Problem with a custom slot of a qlabel

    QLabel doesn't have a slot displayIzquierda(int)

  3. #3

    Default Re: Problem with a custom slot of a qlabel

    But... do i create a custom slot of a Qlabel?

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Problem with a custom slot of a qlabel

    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

  5. #5

    Default Re: Problem with a custom slot of a qlabel

    Quote Originally Posted by mentalmushroom View Post
    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!

  6. #6
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Problem with a custom slot of a qlabel

    connect the signal to the slot of your class, not qlabel

  7. #7

    Default Re: Problem with a custom slot of a qlabel

    Thanks!!!!!! Now it works!

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

Similar Threads

  1. QPushButton with a custom QLabel
    By shadyabhi in forum Newbie
    Replies: 9
    Last Post: 13th August 2015, 03:56
  2. Replies: 2
    Last Post: 30th July 2009, 04:58
  3. the simplest custom slot
    By tommy in forum Qt Programming
    Replies: 30
    Last Post: 12th November 2007, 11:18
  4. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 03:38
  5. custom slot + Designer
    By bashamehboob in forum Qt Tools
    Replies: 1
    Last Post: 28th April 2006, 15:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.