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. Event to signal
Forum Updated to NodeBB v4.3 + New Features

Event to signal

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 286 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.
  • A Offline
    A Offline
    Alexey Serebryakov
    wrote on last edited by
    #1

    Hi guys,
    i've try to use event to signal feature but take an errors.

    Header-only feature class EventsToSignals.hpp:

    #ifndef EVENTSTOSIGNALS_H
    #define EVENTSTOSIGNALS_H
     
    #include <QObject>
    #include <QEvent>
     
    class EventsToSignals : public QObject
    {
        Q_OBJECT
        const QEvent::Type type;
    public:
        explicit EventsToSignals(QObject*parent, QEvent::Type t = QEvent::None )
            : QObject(parent), type(t)
        {
            parent->installEventFilter(this);
        }
     
    signals:
        void onEvent(QObject *watched, QEvent *event);
     
    private:
        bool eventFilter(QObject *watched, QEvent *event)
        {
            bool handled = QObject::eventFilter(watched, event);
            if( type==QEvent::None || type==event->type() )
                emit onEvent(watched, event);
            return handled;
        }
    };
     
    template<typename ... Args >
    auto connectEvent(QObject *obj, QEvent::Type t, Args ... args)
    {
        return obj->connect( new EventsToSignals(obj, t), &EventsToSignals::onEvent, args... );
    }
    template<typename ... Args >
    auto connectEvent(QObject *obj, Args ... args)
    {
        return obj->connect( new EventsToSignals(obj), &EventsToSignals::onEvent, args... );
    }
    #endif // EVENTSTOSIGNALS_H
    

    Trying to use main.cpp:

    #include <QApplication>
    #include <QComboBox>
    #include <QDebug>
    #include <QAbstractItemView>
    
    #include "EventsToSignals.hpp"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QComboBox w;
        w.addItems({"a", "bb", "cccc", "ddddd"});
    
        connectEvent( w.view(), QEvent::Show, [](QObject /*watched*/, QEvent /*event*/){
            qDebug()<<"Show popo-up view";
        });
    
        w.show();
        return a.exec();
    }
    
    ..\..\EventToSignal\example\../src/EventsToSignals.hpp:34:90:   required from 'auto connectEvent(QObject*, QEvent::Type, Args ...) [with Args = {qMain(int, char**)::<lambda(QObject, QEvent)>}]'
    ..\..\EventToSignal\example\main.cpp:16:6:   required from here
    C:\Qt\5.15.2\mingw81_32\include/QtCore/qglobal.h:121:63: error: static assertion failed: Signal and slot arguments are not compatible.
     #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                                   ^~~~~~~~~~~~~~~
    C:\Qt\5.15.2\mingw81_32\include/QtCore/qobject.h:328:9: note: in expansion of macro 'Q_STATIC_ASSERT_X'
             Q_STATIC_ASSERT_X((FunctorArgumentCount >= 0),
    

    Help please!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Alexey-Serebryakov said in Event to signal:

      (QObject /watched/, QEvent /event/)

      Don't know if this is thea reason but this signature is wrong. There signal does not emit objects but pointers.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        @Alexey-Serebryakov said in Event to signal:

        (QObject /watched/, QEvent /event/)

        Don't know if this is thea reason but this signature is wrong. There signal does not emit objects but pointers.

        A Offline
        A Offline
        Alexey Serebryakov
        wrote on last edited by
        #3

        @Christian-Ehrlicher Oh! Sorry, my mistakes! :-) Thanks a lot.

        1 Reply Last reply
        1

        • Login

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