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. Make event problem
Qt 6.11 is out! See what's new in the release blog

Make event problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    Hi..
    I try to make a custom event with 2 inputs, the code like this:

    in myclickevent.h:
    @
    #ifndef MYCLICKEVENT_H
    #define MYCLICKEVENT_H

    #include <QObject>
    #include <QEvent>

    class MyClickEvent : public QEvent
    {
    Q_OBJECT
    public:
    MyClickEvent(bool inspace, bool condition_on)
    :QEvent(QEvent::User){}

    private:
    bool inspc;
    bool on;
    };

    #endif // MYCLICKEVENT_H
    @

    in myclickevent.cpp:
    @
    #include "myclickevent.h"

    MyClickEvent::MyClickEvent(bool inspace, bool condition_on):
    QEvent(parent)

    {
    this->inspc = inspace;
    this->on=condition_on;
    }
    @

    But there are error messages in .cpp file:

    1. function "MyClickEvent::MyClickEvent(bool,bool)" already has a body,
      see previous definition of {ctor}

    2. parent undeclared identifier

    please help.

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _rmn
      wrote on last edited by
      #2

      you should leave only one definition of your constructor
      @
      MyClickEvent(bool, bool)
      @

      also, there no declaration of parent variable:
      @
      MyClickEvent::MyClickEvent(bool inspace, bool condition_on):
      QEvent(parent)
      @

      In fact, compiler reports you enough info about problems in your code.. What kind of help do you need?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        romeo.rbw
        wrote on last edited by
        #3

        Thanks for reply, I am still do not understand how to fix the error.

        1 Reply Last reply
        0
        • _ Offline
          _ Offline
          _rmn
          wrote on last edited by
          #4

          You need learn C++ before using Qt.

          I'll try to prompt you
          1st error: you have two implementations of MyClickEvent(bool, bool) constructor: one in .h file, another in .cpp file. You should lave only one of them.

          2nd error is about lines:
          @
          MyClickEvent::MyClickEvent(bool inspace, bool condition_on):
          QEvent(parent)
          @

          what is "parent" here?

          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