Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signals and Slots, update from old to new nomenclature

Signals and Slots, update from old to new nomenclature

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 851 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josz
    wrote on last edited by
    #1

    Hello again,
    After reading the documents, I induced that the equivalent for the next connection:

    connect(tc, SIGNAL(sigCelsiusChanged(int)), ui->lcdCels, SLOT(display(int)) );
    

    would be the next:

    connect(tc, &tempconverter::sigCelsiusChanged,
                ui->lcdCels, &QLCDNumber::display);
    

    but the compiler says:

    C:\Qt\5.10.1\msvc2015\include\QtCore\qobject.h:214: candidate function not viable: no known conversion from 'void (tempconverter::*)(int) __attribute__((thiscall))' to 'const char *' for 2nd argument
    

    please, what I did wrong?
    Thanks in advance

    where tc is my own objetc, here below
    *.h

    #ifndef TEMPCONVERTER_H
    #define TEMPCONVERTER_H
    
    #include <QObject>
    
    class tempconverter : public QObject
    {    
        Q_OBJECT
    
        int m_tempCelsius;
    
    public:
        tempconverter(int tempCelsius = 0, QObject *parent = nullptr);
    
        //Getter Functions
        int getCelsius() const;
        int getFahrenheit() const;
    
    public slots:
        void setCelsius(int);
        void setFahrenheit(int);
    
    signals:
        void sigCelsiusChanged(int);
        void sigFahrenheitChanged(int);
    
    };
    
    #endif // TEMPCONVERTER_H
    

    *.cpp

    #include "tempconverter.h"
    
    tempconverter::tempconverter(int tempCelsius, QObject *parent) :  QObject(parent)
    {
        m_tempCelsius = tempCelsius;
    }
    
    int tempconverter::getCelsius() const
    {
        return m_tempCelsius;
    }
    
    int tempconverter::getFahrenheit() const
    {
        return static_cast<int>((9.0/5.0) * m_tempCelsius + 32);
    }
    
    void tempconverter::setCelsius(int tempCelsius)
    {
        if (m_tempCelsius == tempCelsius) return;
        m_tempCelsius = tempCelsius;
    
        //emit change signal
        emit sigCelsiusChanged(m_tempCelsius);
        emit sigFahrenheitChanged(getFahrenheit());
    }
    
    void tempconverter::setFahrenheit(int tempFahrenheit)
    {
         setCelsius(static_cast<int>(5.0/9.0*(tempFahrenheit - 32)));
    }
    
    
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      The problem is that QLCDNumber::display is overloaded, you can use:

      connect(tc, &tempconverter::sigCelsiusChanged,
                  ui->lcdCels,  QOverload<int>::of(&QLCDNumber::display));
      

      See https://wiki.qt.io/New_Signal_Slot_Syntax#Overload for more infos

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      J 1 Reply Last reply
      8
      • VRoninV VRonin

        The problem is that QLCDNumber::display is overloaded, you can use:

        connect(tc, &tempconverter::sigCelsiusChanged,
                    ui->lcdCels,  QOverload<int>::of(&QLCDNumber::display));
        

        See https://wiki.qt.io/New_Signal_Slot_Syntax#Overload for more infos

        J Offline
        J Offline
        Josz
        wrote on last edited by Josz
        #3

        @VRonin Very kind of you!
        Thank you very much!

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @Josz See also https://doc.qt.io/qt-5/signalsandslots-syntaxes.html for a comparison between the old and new connection syntaxes.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          J 1 Reply Last reply
          4
          • JKSHJ JKSH

            @Josz See also https://doc.qt.io/qt-5/signalsandslots-syntaxes.html for a comparison between the old and new connection syntaxes.

            J Offline
            J Offline
            Josz
            wrote on last edited by
            #5

            @JKSH Thank you

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved