qobject

What is qobject_cast?

馋奶兔 提交于 2019-12-03 17:15:30
问题 Could someone explain in as simple terms as possible (or as simple as you would like) what qobject_cast is, what it does and why we would need to cast one class type to another? Like, I get typecasting in the sense of casting an int as a char or QString maybe to use QMessageBox , but why cast into different classes? 回答1: Before you start learning what qobject_cast is, you would need to know what C++'s dynamic_cast is. Dynamic cast is all about polymorphism. C++'s dynamic cast uses RTTI (Run

Any chance to use non QObject classes with QML

半腔热情 提交于 2019-12-03 14:43:16
As of Exposing Attributes of C++ Types to QML classes used with QML have to be QObject s. Any chance I can use non QObjects s (aka POCO, not derived from QObject , but registered with Qt metasystem)? If not, is there a simple generic wrapping system to make my objects QML compliant. One I can think of is to add dynamic properties to a simple QObject . Or is there a way to implicitly convert to a QML compliant type so I do not need to wrap at all? This is one hot topic actually. I believe you may register your own PODs and pass them around ito and within the QML side (just as black boxes -- w/o

how to pass qobject as argument from signal to slot in qt connect

你。 提交于 2019-12-03 14:28:00
问题 My original code passed a QStringList from the signal to the slot and then returned a QList. Everything worked fine but I needed to change both the QStringList and QList into 2 different subclassed QObjects. Since then I have been receiving errors like "synthesized method first required here" or it simply crashes without any error message. I understand that qt copies all arguments passed in a queued connection and a qobject cannot be copied. So instead of returning a qobject I thought I would

How to expose C++ structs for computations to Qml

我与影子孤独终老i 提交于 2019-12-03 10:43:51
I have the following problem. I am developing a model in C++ and a View in Qml, connecting them via Controllers. In my model I perform multiple calculations. I also offer users of my application the possibility, to write custom event handlers, written in qml. Now I came across a point, where I decided to use Fixed point notation and I have written a corresponding C++ class. Now I want offer the FixedPoint class - including all its operators - to developers, who decide to extend my application in Qml. So far, I offered all data as QProperties, which is required by coding guidelines. But I am

Serializing my custom class in Qt

血红的双手。 提交于 2019-12-03 08:44:38
问题 i use Reading/writing QObjects is it true? i serialize a class with it but when deserialize it isn't the original class! what can i do? this is my base class header: class Base : public QObject { Q_OBJECT public: explicit Base(QObject *parent = 0); }; QDataStream &operator<<(QDataStream &ds, const Base &obj); QDataStream &operator>>(QDataStream &ds, Base &obj) ; and .cpp is: Base::Base(QObject *parent) : QObject(parent) { } QDataStream &operator<<(QDataStream &ds, const Base &obj) { for(int i

how to pass qobject as argument from signal to slot in qt connect

邮差的信 提交于 2019-12-03 03:30:45
My original code passed a QStringList from the signal to the slot and then returned a QList. Everything worked fine but I needed to change both the QStringList and QList into 2 different subclassed QObjects. Since then I have been receiving errors like "synthesized method first required here" or it simply crashes without any error message. I understand that qt copies all arguments passed in a queued connection and a qobject cannot be copied. So instead of returning a qobject I thought I would create both qobjects prior to emitting the signal. Then I would pass references to each object, modify

Qt 5 assign slot with parameters to a QPushButton

一个人想着一个人 提交于 2019-12-03 03:09:32
I have a Qt application on C++ and I want to assign a slot to a QPushButton. But I want to pass some arguments because I have more than one QPushButton doing similar thing so I want one function but with a parameter in it but Qt keeps saying me that there is no slot like this. Can someone tell me why and how should I do it? Thank you in advance In the .h file I have: (it was private in the beginning but I changed it in searching of the problem) public slots: void handleButton(int row, int col); Then in the .cpp: void fieldWindow::handleButton(int row, int col){ cout << row << " " << col <<

Serializing my custom class in Qt

随声附和 提交于 2019-12-02 22:38:57
i use Reading/writing QObjects is it true? i serialize a class with it but when deserialize it isn't the original class! what can i do? this is my base class header: class Base : public QObject { Q_OBJECT public: explicit Base(QObject *parent = 0); }; QDataStream &operator<<(QDataStream &ds, const Base &obj); QDataStream &operator>>(QDataStream &ds, Base &obj) ; and .cpp is: Base::Base(QObject *parent) : QObject(parent) { } QDataStream &operator<<(QDataStream &ds, const Base &obj) { for(int i=0; i<obj.metaObject()->propertyCount(); ++i) { if(obj.metaObject()->property(i).isStored(&obj)) { ds <

Qt: No metadata by meta.enumeratorCount() for enum in Q_OBJECT, why?

我怕爱的太早我们不能终老 提交于 2019-12-02 13:40:16
问题 I have the following class, where I try to obtain some metadata of an enum MyEnum . However, when looping over meta.enumeratorCount() its count is always 0. Basically I was follwing this example here. In order to find the problem, I was trying the same with methods too, same problem - method count 0. Code compiles, no errors no warnings. Must be a silly mistake .... maybe you can help me class FsxSimConnectQtfier : public QObject { Q_OBJECT public: explicit FsxSimConnectQtfier(QObject *parent

Qt: No metadata by meta.enumeratorCount() for enum in Q_OBJECT, why?

我与影子孤独终老i 提交于 2019-12-02 06:04:45
I have the following class, where I try to obtain some metadata of an enum MyEnum . However, when looping over meta.enumeratorCount() its count is always 0. Basically I was follwing this example here . In order to find the problem, I was trying the same with methods too, same problem - method count 0. Code compiles, no errors no warnings. Must be a silly mistake .... maybe you can help me class FsxSimConnectQtfier : public QObject { Q_OBJECT public: explicit FsxSimConnectQtfier(QObject *parent = 0); enum MyEnum { G1, G2 }; static const QString simConnectExceptionToString(const DWORD id); };