При первом использовании QSettings, Qt сразу-же грузит все в QVariant-ы, и если часть иcпользуемых метатипов не зарегена, код в qvariant.cpp с треском рушит программу: "QVariant::load(QDataStream &s): type %s unknown to QVariant.". В доках про это ни слова, но зарегить все типы на момент запуска проги обычно не возможно.
это Qt глючит или меня?
QSettings и метатипы
Модератор: Модераторы разделов
-
tarkus
- Сообщения: 38
QSettings и метатипы
Ушел на прогулку до выхода KDE4. Всем удачи! :)
-
Liksys
- Сообщения: 2910
Re: QSettings и метатипы
Хых, что-то не замечал этого... Напиши тестовый код, выложи, я проверю.
-
tarkus
- Сообщения: 38
Re: QSettings и метатипы
лови.
на 2й раз она вылетает с:
we should always get here.
QVariant::load(QDataStream &s): type CustomType unknown to QVariant.
Код: Выделить всё
#include <QtCore>
struct CustomType {
QString value, anotherValue;
};
Q_DECLARE_METATYPE(CustomType)
QDataStream &operator<<(QDataStream &out, const CustomType &ct);
QDataStream &operator>>(QDataStream &in, CustomType &ct);Код: Выделить всё
#include "test.h"
QDataStream &operator<<(QDataStream &out, const CustomType &ct) {
out << ct.value << ct.anotherValue;
return out;
}
QDataStream &operator>>(QDataStream &in, CustomType &ct) {
in >> ct.value;
in >> ct.anotherValue;
return in;
}
int main(int argc, char *argv[]) {
QCoreApplication *app = new QCoreApplication(argc, argv);
app->setOrganizationName("CoolSoftware");
app->setApplicationName("MegaSuperUtil");
fprintf(stderr, "we should always get here.\n");
QSettings qsetts;
fprintf(stderr, "we wont get here 2nd time.\n");
qsetts.beginGroup("general");
int numRuns = qsetts.value("numRuns", 0).toInt();
++numRuns;
qsetts.setValue("numRuns", numRuns);
qsetts.endGroup();
fprintf(stderr, "and here we also wont get on the second run.\n");
qRegisterMetaType<CustomType>("CustomType");
qRegisterMetaTypeStreamOperators<CustomType>("CustomType");
qsetts.beginGroup("specific");
CustomType ct = qsetts.value("customTypedValue",
QVariant::fromValue(CustomType())).value<CustomType>();
ct.value = "foo";
ct.anotherValue = "bar";
qsetts.setValue("customTypedValue", QVariant::fromValue(ct));
qsetts.endGroup();
fprintf(stderr, "bay-bay!\n");
return 0;
}на 2й раз она вылетает с:
we should always get here.
QVariant::load(QDataStream &s): type CustomType unknown to QVariant.
Ушел на прогулку до выхода KDE4. Всем удачи! :)
-
Liksys
- Сообщения: 2910
Re: QSettings и метатипы
[liksys@max qttest]$ ls
main.cpp main.o Makefile qttest qttest.pro test.h
[liksys@max qttest]$ ./qttest
we should always get here.
we wont get here 2nd time.
and here we also wont get on the second run.
bay-bay!
[liksys@max qttest]$ ./qttest
we should always get here.
we wont get here 2nd time.
and here we also wont get on the second run.
bay-bay!
[liksys@max qttest]$ ./qttest
we should always get here.
we wont get here 2nd time.
and here we also wont get on the second run.
bay-bay!
[liksys@max qttest]$ ./qttest
we should always get here.
we wont get here 2nd time.
and here we also wont get on the second run.
bay-bay!
[liksys@max qttest]$ ./qttest
we should always get here.
we wont get here 2nd time.
and here we also wont get on the second run.
bay-bay!
Какая версия Qt? Где брал?
-
tarkus
- Сообщения: 38
Re: QSettings и метатипы
странно... версия 4.1.4, шла в комплекте с Мандривой 2007
Код: Выделить всё
[exa@localhost ~]$ cat /usr/lib/qt4/include/Qt/qglobal.h | grep QT_VERSION_STR
#define QT_VERSION_STR "4.1.4"
[exa@localhost ~]$ uname --all
Linux localhost 2.6.17-5mdv #1 SMP Wed Sep 13 14:32:31 EDT 2006 i686 Intel(R) Pentium(R) 4 CPU 2.60GHz GNU/LinuxУшел на прогулку до выхода KDE4. Всем удачи! :)
-
Liksys
- Сообщения: 2910
Re: QSettings и метатипы
Она сыровата, попробуй обновить. У меня обычно всегда свежай Qt - щас стоит 4.3.0, багов не замечено.
[liksys@max ~]$ rpm -qa|grep qt4
qt4-mysql-4.3.0-9.fc7.1
qt4-postgresql-4.3.0-9.fc7.1
qt4-4.3.0-9.fc7.1
qt4-doc-4.3.0-9.fc7.1
qt4-qsa-devel-1.2.2-4.fc7
qt4-x11-4.3.0-9.fc7.1
qt4-sqlite-4.3.0-9.fc7.1
qt4-odbc-4.3.0-9.fc7.1
qt4-qsa-1.2.2-4.fc7
qt4-devel-4.3.0-9.fc7.1
-
tarkus
- Сообщения: 38
Re: QSettings и метатипы
Ясно.
А 4.1 меня вполне устраивает стабильностью, но оказывается проскакивают такие хитрые баги.
А 4.1 меня вполне устраивает стабильностью, но оказывается проскакивают такие хитрые баги.
Ушел на прогулку до выхода KDE4. Всем удачи! :)