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. Not use QCustomEvent class in Qt 4.7.4
Forum Updated to NodeBB v4.3 + New Features

Not use QCustomEvent class in Qt 4.7.4

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.6k 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.
  • P Offline
    P Offline
    phamvanan
    wrote on last edited by
    #1

    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.

    -PVA-

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phamvanan
        wrote on last edited by
        #3

        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.

        -PVA-

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            phamvanan
            wrote on last edited by
            #5

            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.

            -PVA-

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              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 )
              {
              ...
              }
              @

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • P Offline
                P Offline
                phamvanan
                wrote on last edited by
                #7

                Thanks for your answer and quickly edit.
                An.

                -PVA-

                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