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. [SOLVED] New signal/slot doesn't work in the same class with different instances

[SOLVED] New signal/slot doesn't work in the same class with different instances

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 1.9k 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    Hi!

    I tried to connect a signal and a slot of the same class to different instances using the new connect-syntax. Result: doesn't work. The signal is emitted but the slot is never called. If i use the old syntax with SIGNAL() and SLOT() is works with no problems. Any idea why?

    Here's the class header:
    @
    #ifndef PLUGINWIDGET_H
    #define PLUGINWIDGET_H

    #include <QWidget>
    #include "../generallibrary_global.h"

    class LogTextEdit;
    class LogWidget;

    /*!
    \brief

    */
    class PluginWidget : public QWidget
    {
    Q_OBJECT
    public:

    /*!
     \brief
    
     \param parent
    */
    explicit PluginWidget(QWidget * parent);
    
    /*!
     \brief
    
     \return LogTextEdit
    */
    LogTextEdit * getLogTextEdit() const;
    
    /*!
     \brief
    
     \param getLogTextEdit
    */
    void setLogTextEdit(LogTextEdit *getLogTextEdit);
    
    /*!
     \brief
    
    */
    void show();
    
    /*!
     \brief
    
     \return LogWidget
    */
    LogWidget *getLogWidget() const;
    
    /*!
     \brief
    
     \param getLogWidget
    */
    void setLogWidget(LogWidget *getLogWidget);
    
    /*!
     \brief
    
     \return QWidget
    */
    QWidget *ContainerWidget() const;
    
    /*!
     \brief
    
     \param ContainerWidget
    */
    void setContainerWidget(QWidget *ContainerWidget);
    
    /*!
     \brief
    
    */
    virtual void initAfterShow() = 0;
    
    /*!
     \brief
    
    */
    virtual void initBeforeShow() = 0;
    
    QString PluginDirectory() const;
    
    void setPluginDirectory(const QString &PluginDirectory);
    
    void registerToGetData(QString datatype);
    

    signals:

    void dataSignal(QString datatype, void * data);
    

    public slots:

    void dataSlot(QString datatype, void * data);
    

    private:
    LogTextEdit * m_logTextEdit; /*!< TODO /
    LogWidget * m_logWidget;
    int m_PluginIndex;
    QWidget * m_ContainerWidget; /
    !< The container in which this widget is nested */
    QString m_sPluginDirectory;
    bool m_wasShownBefore;
    QStringList m_sDataTypes;
    };

    #endif // PLUGINWIDGET_H

    @

    And now the way i connect it:

    @
    connect(pluginoutputdata->getPluginMainWidget(), &PluginWidget::dataSignal, plugininputdata->getPluginMainWidget(), &PluginWidget::dataSlot);
    @

    It simply does not work. Thank you for your help and have a nice day :-)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      What errros are you getting?

      1 Reply Last reply
      0
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

        Hi!

        Ups...i've forgotten the error:

        @QObject::connect: signal not found in@

        Thank you!

        1 Reply Last reply
        0
        • jensen82J Offline
          jensen82J Offline
          jensen82
          wrote on last edited by
          #4

          And i'm using a derived class...

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zarkon
            wrote on last edited by
            #5

            Would it help if you add the function mask?

            @connect(pluginoutputdata->getPluginMainWidget(), &PluginWidget::dataSignal(QString, void *) , plugininputdata->getPluginMainWidget(), &PluginWidget::dataSlot(QString, void *));@

            1 Reply Last reply
            0
            • jensen82J Offline
              jensen82J Offline
              jensen82
              wrote on last edited by
              #6

              Hi!

              No, doesn't help. There must be a trick. I'm sure i'm not the first person with this problem. Maybe i used the wrong search terms to find a post here...

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #7

                Hmm, maybe something with the vtables, in your class declaration:
                @QWidget * m_ContainerWidget; /*!< The container in which this widget is nested */@

                so if pluginoutputdata->getPluginMainWidget() inside your connect() returns a QWidget instead of a PluginWidget then dataSignal/dataSlot would be unknown methods.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  t3685
                  wrote on last edited by
                  #8

                  Are you sure that using the regular SIGNAL/SLOT macros the connection works? Did you check the return value?

                  1 Reply Last reply
                  0
                  • jensen82J Offline
                    jensen82J Offline
                    jensen82
                    wrote on last edited by
                    #9

                    Yes. The old way works. But i found it. It's solved.

                    The problem was that i subclassed it and did not use the right way. The slot in the base class was not virtual. Thats it.

                    Thank you for your help!

                    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