I want to return the id of a previously registered custom class by using a QString. I’ve tried the following, but all of them return QMetaType::UnknownType
QString name = "MyClass";
QMetaType::type(name.toLatin1().data()); // fail
QMetaType::type(name.toUtf8().data()); // fail
QMetaType::type(name.toLocal8Bit() .data()); // fail
char *chars = new char[name.length()];
strcpy(chars, name.toStdString().c_str());
QMetaType::type(chars); // fail
I thought there was a bug with QMetaType or Q_DECLARE_METATYPE. This is not the case, since the following succeeded:
QMetaType::type("MyClass"); // success
Since no QString object is passed, the parameter is (I assume) directly used as a char*. Does anyone know how to correctly decode a QString to a char* so that QMetaType::type works correctly?
EDIT: Does this maybe have something to do with the terminating-character?
↧