Questions tagged [qgadget]

The Q_GADGET macro is a lighter version of the Q_OBJECT macro for classes that do not inherit from QObject but still want to use some of the reflection capabilities offered by QMetaObject. Just like the Q_OBJECT macro, it must appear in the private section of a class definition.

The Q_GADGET macro is a lighter version of the Q_OBJECT macro for classes that do not inherit from QObject but still want to use some of the reflection capabilities offered by QMetaObject. Just like the Q_OBJECT macro, it must appear in the private section of a class definition.

Q_GADGET makes a class member, staticMetaObject, available. staticMetaObject is of type QMetaObject and provides access to the enums declared with Q_ENUMS.

Since Qt 5.5 Q_GADGETs can have Q_ENUM, Q_PROPERTY and Q_INVOKABLE but, differently from Q_OBJECT, they cannot declare signals or slots. Thanks to these new features, Q_GADGET macro can be used to register so called custom QML value type as explained in the documentation.

11 questions
15
votes
2 answers

How to get human-readable event type from QEvent?

I want to debug event handling code and would like to convert QEvent::Type enum's value to a human-readable string. QEvent has a Q_GADGET macro, so presumably there's a way of pulling that off?
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
4
votes
1 answer

Passing Q_GADGET as signal parameter from C++ to QML

Can't get a property of a C++ object inside a QML code. Object is passed as a parameter to the signal. Expected that in QML, the property text of the Record object can be extracted. And the value should be abc. QML sees the object as…
Velkan
  • 7,067
  • 6
  • 43
  • 87
2
votes
1 answer

Q_GADGET Unknown method return type

I have a class MyWindow. This class call MyWindow.h class MyWindow : public QObject { Q_OBJECT Q_PROPERTY(int nbMatch READ GetNbMatch NOTIFY matchChangedQMLL) public: explicit MyWindow(QObject *parent = nullptr); explicit…
mm98
  • 409
  • 1
  • 6
  • 18
2
votes
1 answer

How to expose a pointer to a Q_GADGET to QML through a Q_PROPERTY

I have a Q_GADGET MyGadget defined in a file mygadget.h #include class MyGadget { Q_GADGET Q_PROPERTY(int value READ value CONSTANT) public: MyGadget() = default; MyGadget(int i) : _value{i} { } int…
Corristo
  • 4,911
  • 1
  • 20
  • 36
1
vote
1 answer

Getting 'unregistered datatype' error in QML when Q_GADGET struct is in a separate header file

I have a custom struct which I use as a Q_PROPERTY type in a QMediaPlayer derived class. But here's the code: struct VideoMeta { Q_GADGET Q_PROPERTY(int width MEMBER width) Q_PROPERTY(...) .... public: int width; …
1
vote
1 answer

Unable to iterate over a Qt enumeration

I am trying to iterate over an enumeration. class MyEnumClass : public QObject { Q_GADGET Q_ENUMS(MyEnum) public: enum MyEnum { a, b, c }; MyEnumClass(QObject *parent = 0){} …
Thalia
  • 13,637
  • 22
  • 96
  • 190
1
vote
2 answers

Object::property ( const char * name ) const returning empty QVariant

My class has enum property, i wish to access this property using QObject*. When calling QVariant QObject::property ( const char * name ) const return value is empty QVariant of enum type. Consider the following code: /* Interface class */ class…
krizajb
  • 1,715
  • 3
  • 30
  • 43
1
vote
1 answer

Qt, enums and metaobject compiler

I have a following user class: class MyLine : public QLineEdit { Q_OBJECT Q_ENUMS(Base::LineState) public: explicit MyLine (QWidget *parent = 0); }; Also I have base class containing all global enums: class Base { Q_GADGET …
Queue Overflow
  • 364
  • 1
  • 2
  • 12
0
votes
1 answer

Is it possible to fix failed build of multiple inheritance from Q_GADGET with Clang and Qt 6?

In one my project, a build on MacOS under GitHub action: macos: name: macos runs-on: macos-11 Subproject JKQtPlotter fails with: [ 64%] Building CXX object…
Igor Mironchik
  • 582
  • 4
  • 17
0
votes
1 answer

Accessing Structure inside a structure in QML

Previously I posted a question on how to access structures in QML and got perfect answers from some awesome people and now i need to know is there any way to access structure inside a structure in QML, Following is the code : //MyNewStruct struct…
pra7
  • 834
  • 2
  • 21
  • 50
0
votes
3 answers

Why is my slot not being called?

I have this class: class CustomEdit : public QTextEdit { Q_GADGET public: CustomEdit(QWidget* parent); public slots: void onTextChanged (); }; CustomEdit::CustomEdit(QWidget* parent) : QTextEdit(parent) { connect( this,…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281