qmetaobject

How to convert Q_ENUM to QString for QT > 5.11 most efficient way?

不问归期 提交于 2021-02-05 08:51:35
问题 I read several advices how to get an actual QString from a Q_ENUM value. Below are 3 possible ways, I came up with, that are compilable constructs in QT5.11.1 What of them should one prefer and why? void MainWindow::setErrorText(QCanBusDevice::CanBusError error) { QString errorString; QDebug(&errorString) << error; ui->statusBar->showMessage("Error occured: " + errorString); // QT4 ? const QMetaObject& mo = QCanBusDevice::staticMetaObject; QMetaEnum me = mo.enumerator(mo.indexOfEnumerator(

How can I find a Qt metaobject instance from a class name?

99封情书 提交于 2019-12-21 13:36:10
问题 Is there a way to find the QMetaObject instance of a class, given the class name? what I like to do is to load objects from disk, but for this to happen, I need a way to retrieve a QMetaObject instance using the name of a class, in order to use the QMetaObject to create an instance. 回答1: You should be able to do this with QMetaType. You might need Q_DECLARE_META_TYPE() and/or qRegisterMetaType() to make your types known. Then it should work roughly like in this example from the link: int id =

How to find out from the slot which signal has called this slot?

偶尔善良 提交于 2019-12-21 04:32:18
问题 I mean if I have many different signals which are connected to the same slot. I saw this question but can't understand the link in the answer. Can you give me simple example? 回答1: I think you can use this method: [protected] int QObject::​senderSignalIndex() const From Qt documentation: Returns the meta-method index of the signal that called the currently executing slot , which is a member of the class returned by sender(). If called outside of a slot activated by a signal, -1 is returned.

Class name from QMetaProperty

删除回忆录丶 提交于 2019-12-11 12:23:38
问题 I am working on making my own designer widget that looks and functions like qt. But now I needed to know how the property is created. I knew we can get the properties of an widget using QMetaObject and QMetaProperty but my question is will I be able to get the class name of each property. Like object name property comes from QObject and geomentry property comes from QWidget . Is it so that i should hard code myself to model or is there a way to get the classInfo from property. I have attached

Is it possible to disconnect all of a QObject's connections without deleting it

痞子三分冷 提交于 2019-12-04 16:34:41
问题 I have a QObject A, this is connected to another QObject B. Now I want A to connect to C, a third QObject and to completely disconnect from B. Easy peasy! Trouble is I have a lot of of A's each with their own set of signals and slots (B's/C's are more generic). So far I have been manually making a connect and a disconnect method for each different class type. The methods are basically copies of each other exchanging the connect for disconnect call, going against the don't repeat yourself). So

How can I find a Qt metaobject instance from a class name?

一个人想着一个人 提交于 2019-12-04 05:54:54
Is there a way to find the QMetaObject instance of a class, given the class name? what I like to do is to load objects from disk, but for this to happen, I need a way to retrieve a QMetaObject instance using the name of a class, in order to use the QMetaObject to create an instance. You should be able to do this with QMetaType . You might need Q_DECLARE_META_TYPE() and/or qRegisterMetaType() to make your types known. Then it should work roughly like in this example from the link: int id = QMetaType::type("MyClass"); if (id == 0) { void *myClassPtr = QMetaType::construct(id); ... QMetaType:

How to go about serializing a large, complex object?

北战南征 提交于 2019-12-01 11:22:32
I have a " User " class with 40+ private variables including complex objects like private/public keys (QCA library), custom QObjects etc. The idea is that the class has a function called sign() which encrypts, signs, serializes itself and returns a QByteArray which can then be stored in a SQLite blob. What's the best approach to serialize a complex object? Iterating though the properties with QMetaObject ? Converting it to a protobuf object? Could it be casted to a char array? Could it be casted to a char array? No, because you'd be casting QObject 's internals that you know nothing about,

How to go about serializing a large, complex object?

社会主义新天地 提交于 2019-12-01 09:03:18
问题 I have a " User " class with 40+ private variables including complex objects like private/public keys (QCA library), custom QObjects etc. The idea is that the class has a function called sign() which encrypts, signs, serializes itself and returns a QByteArray which can then be stored in a SQLite blob. What's the best approach to serialize a complex object? Iterating though the properties with QMetaObject ? Converting it to a protobuf object? Could it be casted to a char array? 回答1: Could it