Not use QCustomEvent class in Qt 4.7.4



  • Hi all,
    I try use QCustomEvent but
    Although,
    @#include <QCustomEvent>@
    When i use it,
    @ QApplication::postEvent(QApplication::instance(), new QCustomEvent(MyEvent));@
    I get error:
    @error: C2061: syntax error : identifier 'QCustomEvent'@

    Thanks.


  • Moderators

    my fault... the link wasn't still up to date.
    QCustomEvent is only available if your Qt4 is built with Qt3 support.

    For "Qt4":http://qt-project.org/doc/qt-4.7/porting4.html#id-4cb0a3dc-e4b9-45f1-be70-546d53022c96 just leave out the QCustomEvent and keep proceeding.... meaning just send the event directly without wrapping it in a QCustomEvent.
    The MyEvent object should be a custom class derived from QEvent. In there set all the data you need.



  • Hi,
    In Qt 4.7, Which replace to QCustomEvent?
    I have two Objects, one is Copier class, else MainWindow class.
    At copier class I want call postEvent function to Mainwindow class with a data. In mainwindow class how to get data event?
    Thanks.


  • Lifetime Qt Champion

    Hi,

    In the event filter, check against your event type and then cast it to your class so you can access your data.



  • Hi,
    I found a document link about "event and fitter event":http://qt-project.org/doc/qt-4.8/eventsandfilters.html
    I see a example fitter event but i don't understand what's MyCustomEventType ?
    I created a class MyCustomEvent as below:
    @
    #include <QEvent>

    class MyCustomEvent : public QEvent{
    explicit MyCustomEvent(QObject *parent = 0);
    public:
    qint64 byteCopied;
    };
    #endif // MYCUSTOMEVENT_H

    @
    When I postEvent,
    @
    MyCustomEvent *event;
    event->byteCopied = 1204;
    QApplication::postEvent(QApplication::instance(), event);
    @
    How to check type and get my data in eventFilter function.
    @
    bool MainWindow::eventFilter(QObject *object, QEvent *event){

    }
    @
    Thanks,
    An.


  • Moderators

    you will need to register your event type somewhere early in your application ( main() or MainWindow constructor ):

    you MyCustomEvent implementation:
    @
    #include <QEvent>

    class MyCustomEvent : public QEvent
    {
    public:
    explicit MyCustomEvent(QObject *parent = 0) : QEvent(MyCustomEvent::customType)
    {
    }

    qint64 byteCopied;
    static const QEvent::Type customType;
    

    };
    #endif // MYCUSTOMEVENT_H
    @

    in main.cpp
    @
    #include "MyCustomEvent.h"

    const QEvent::Type MyCustomEvent::customType = static_castQEvent::Type(QEvent::registerEventType());

    int main()
    {
    QApplication app;
    ...
    }
    @

    in your eventFilter():
    @
    if( event->type() == MyCustomEvent::customType )
    {
    ...
    }
    @



  • Thanks for your answer and quickly edit.
    An.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.