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. How to have a function triggered by an event
Forum Updated to NodeBB v4.3 + New Features

How to have a function triggered by an event

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.4k 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.
  • M Offline
    M Offline
    Moschops
    wrote on last edited by
    #1

    I have a class (which inherits from QSortFilterProxyModel, so it is a QObject).

    I would like the class to act on a @QEvent::LanguageChange@

    All my QWidget derived classes have a very helpful QWidget::changeEvent function that seems to get called automatically when the event happens.

    How can I have a specific function in the QSortFilterProxyModel derived object be called as well? I was hoping to find some kind of "register to receive THIS kind of event, by having THIS class function called" mechanism.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      In your parent class add the connection to it?
      All QObject derived classes have the build in LanguageChange event.
      Read this: "QEvent":http://qt-project.org/doc/qt-5/QEvent.html#details
      But do you really want the proxy to handle this? Or should the base data in your model itself do it? IMHO you should do it where the data is hold, so in the model data.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moschops
        wrote on last edited by
        #3

        Ah, is it done with deliberately made connections? I had the idea from somewhere that QEvents happened in some kind of global type environment (or at least, something with a wide scope) and that QObjects could effectively ask to be triggered by any event.

        I might be misremembering that from a totally different message-handling system I worked with a few years ago. I've got enough frameworks in my head now that some of them blur together :(

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          QObjects get event automatic from the QApplication or from their local event loop AFAIK.

          When somewhere the qApp->setTranslator is called, every widget should get someting like this:

          @
          void MainWindow::changeEvent(QEvent* event)
          {
          if (event->type() == QEvent::LanguageChange)
          {
          // retranslate designer form
          ui->retranslateUi(this);
          }

          // remember to call base class implementation
          QWidget::changeEvent(event);
          

          }
          @

          Greetz, Jeroen

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Moschops
            wrote on last edited by
            #5

            Yes, the QWidgets all do; I have other QObjects that also need to know.

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Hi, If those QObjects have parents, those parents will continue those events downwards. So, that's why in my example, i added the QWidget::changeEvent(event) code. The same goes for QObjects!
              Did you read the QEvent class I mentioned before?

              Greetz, Jeroen

              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