2018-01-21 21:48:02 +08:00
|
|
|
|
#include "widget.h"
|
2018-06-09 01:38:46 +08:00
|
|
|
|
#include <QQtApplication>
|
2018-01-21 21:48:02 +08:00
|
|
|
|
#include "qqtdictionary.h"
|
|
|
|
|
|
|
|
|
|
int main ( int argc, char* argv[] )
|
|
|
|
|
{
|
2018-06-09 01:38:46 +08:00
|
|
|
|
QQtApplication a ( argc, argv );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
QString tt;
|
|
|
|
|
tt = QString ( "%1" ).sprintf ( "%4d", 13 );//" 13"
|
|
|
|
|
tt = QString ( "%1" ).arg ( 13, 4, 10 );
|
|
|
|
|
pline() << tt;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
QQtWidgetFactory::registerObject<QPushButton>();
|
|
|
|
|
QObject* obj = QQtWidgetFactory::createObject ( "QPushButton" );
|
|
|
|
|
pline() << obj->inherits ( "QWidget" );
|
|
|
|
|
pline() << obj->inherits ( "QPushButton" );
|
|
|
|
|
pline() << obj->inherits ( "QObject" );
|
|
|
|
|
obj->setObjectName ( "bbb" );
|
|
|
|
|
pline() << obj->objectName();
|
2018-04-22 16:00:14 +08:00
|
|
|
|
QQtObjectManager::registerObject ( obj );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
//对QQtDictionary的使用进行测试。
|
|
|
|
|
QQtDictionary d0;
|
2018-01-21 21:48:02 +08:00
|
|
|
|
d0["cc"] = "dd";
|
|
|
|
|
pline() << d0["cc"].getValue();
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary d1;
|
|
|
|
|
QQtDictionary d2 ( QVariant ( "CCCC" ) );
|
2018-06-13 12:14:37 +08:00
|
|
|
|
d1.addChild ( d2 );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
pline() << d1[0].getValue();
|
|
|
|
|
d1[0] = "ff";
|
|
|
|
|
pline() << d1[0].getValue();
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary d3;
|
2018-01-21 21:48:02 +08:00
|
|
|
|
d3["cc"]["dd"] = "ee";
|
|
|
|
|
pline() << d3["cc"]["dd"].getValue().toString();
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary d4;
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < 5; i++ )
|
|
|
|
|
{
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary d ( QVariant ( QString::number ( i ) ) );
|
2018-06-13 12:14:37 +08:00
|
|
|
|
d4.addChild ( d );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pline() << d4.count();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < d4.count(); i++ )
|
|
|
|
|
{
|
|
|
|
|
pline() << d4[i].getValue().toString();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary d5;
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
/*后续有map操作,这一步就没有用了*/
|
2018-06-13 12:14:37 +08:00
|
|
|
|
d5.addChild ( "5.7" );
|
|
|
|
|
d5.addChild ( "5.8" );
|
|
|
|
|
d5.addChild ( "5.9" );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
/*后续有map操作,这一步就没有用了*/
|
2018-06-13 12:14:37 +08:00
|
|
|
|
d5["5.7"].addChild ( "5.7.2" );
|
|
|
|
|
d5["5.7"].addChild ( "5.7.3" );
|
|
|
|
|
d5["5.7"].addChild ( "5.7.4" );
|
|
|
|
|
|
|
|
|
|
d5["5.7"]["5.7.4"].addChild ( "xxx.dmg" );
|
|
|
|
|
d5["5.7"]["5.7.4"][0].addChild ( "xxx.dmg" );
|
|
|
|
|
d5["5.7"]["5.7.4"][0].addChild ( "2017-12-12" );
|
|
|
|
|
d5["5.7"]["5.7.4"][0].addChild ( "1.2G" );
|
|
|
|
|
d5["5.7"]["5.7.4"][0].addChild ( "Detail" );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
d5["5.7"]["5.7.4"][0].insertChild ( 4, "Detail2" );
|
|
|
|
|
|
|
|
|
|
//pline() << "\n" << d5;
|
|
|
|
|
pline() << "\n" << d5["5.7"];
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionaryMapIterator itor ( d5["5.7"].getMap() );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
while ( itor.hasNext() )
|
|
|
|
|
{
|
|
|
|
|
itor.next();
|
|
|
|
|
pline() << "\n" << itor.key() << itor.value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pline () << d5["5.7"]["5.7.4"][0].getType();
|
|
|
|
|
pline () << d5["5.7"]["5.7.4"][0].count();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < d5["5.7"]["5.7.4"][0].count(); i++ )
|
|
|
|
|
{
|
|
|
|
|
pline() << d5["5.7"]["5.7.4"][0][i].getValue().toString();
|
|
|
|
|
}
|
2018-04-18 09:55:19 +08:00
|
|
|
|
pline() << d5["5.7"]["5.7.4"][0];
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary node = d5;
|
2018-01-21 21:48:02 +08:00
|
|
|
|
pline() << node["5.7"]["5.7.4"][0][0].getValue().toString();
|
|
|
|
|
|
|
|
|
|
/*在这里有list操作,前边"5.7"的map就没有用了*/
|
|
|
|
|
/*但是再过去做过的list类型的操作都会被保留,也就是说中间出现过概念错误,没问题还保留着*/
|
2018-06-13 12:14:37 +08:00
|
|
|
|
d5["5.7"].addChild ( "5.7.5" );
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < d5["5.7"].count(); i++ )
|
|
|
|
|
{
|
|
|
|
|
pline() << d5["5.7"][i].getValue().toString();
|
|
|
|
|
}
|
2018-04-18 09:55:19 +08:00
|
|
|
|
pline() << d5["5.7"];
|
2018-01-21 21:48:02 +08:00
|
|
|
|
|
|
|
|
|
char* cc = NULL;
|
|
|
|
|
char* bb = "ddddd";
|
|
|
|
|
|
|
|
|
|
QString ccq = QString ( "%1%2" ).arg ( cc ).arg ( bb );
|
|
|
|
|
pline() << ccq;
|
|
|
|
|
|
|
|
|
|
//Widget w;
|
|
|
|
|
//w.show();
|
|
|
|
|
|
2018-06-13 12:14:37 +08:00
|
|
|
|
//QQtDictionary addChild函数存在一个问题,在这里测试是否解决。
|
2018-04-17 19:32:16 +08:00
|
|
|
|
//内部实现使用list的append函数,会引用外部的类实例,这导致在free空间的时候,存在很多莫名其妙的二次free,尤其外部实例和QObject关联的时候。
|
2018-04-26 16:37:54 +08:00
|
|
|
|
//现在内部实现使用push_back,这里检测QQtDictionary还有没有二次free这个bug。
|
|
|
|
|
QQtDictionary* n0 = new QQtDictionary ( QVariant ( "This is a value" ) );
|
2018-04-17 19:32:16 +08:00
|
|
|
|
//这里打印一下n0的值和地址
|
|
|
|
|
pline() << n0->getValue().value<QString>();
|
|
|
|
|
pline() << hex << n0->getValue().constData();
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary t0;
|
2018-06-13 12:14:37 +08:00
|
|
|
|
//这里addChild,t0变成一个list。
|
|
|
|
|
t0.addChild ( *n0 );
|
2018-04-17 19:32:16 +08:00
|
|
|
|
|
|
|
|
|
//这里更改外部实例的值,显然外部实例的值已经改变了。
|
|
|
|
|
n0->getValue().setValue<QString> ( "This is a changed value" );
|
|
|
|
|
|
|
|
|
|
//为了证实这一点,这里打印值
|
|
|
|
|
pline() << "外部空间的值" << n0->getValue().value<QString>();
|
|
|
|
|
//这里可能还有一个疑惑,新的值是不是占据了新的空间?其实,没有。这里打印地址证实。
|
|
|
|
|
pline() << "外部空间的地址" << hex << n0->getValue().constData();
|
|
|
|
|
|
|
|
|
|
//这里删除外部实例n0,不用把n0置零,不必要,n0和申请的存储空间是两回事。
|
|
|
|
|
delete n0;
|
|
|
|
|
//但是,置零,规范一点。
|
|
|
|
|
n0 = NULL;
|
|
|
|
|
|
|
|
|
|
//外部的空间的值被改变了,并且删除了,内部空间的值,发生了什么?
|
|
|
|
|
//现在检查,内部的值是多少?
|
|
|
|
|
pline() << "检测内部空间的值:" << t0[0].getValue().value<QString>();
|
|
|
|
|
pline() << "检测内部空间的地址:" << hex << t0[0].getValue().constData() ;
|
|
|
|
|
|
|
|
|
|
//windows
|
2018-04-26 16:37:54 +08:00
|
|
|
|
//经过测试,QQtDictionary内部空间成功和外部空间分离,bug清除。
|
2018-04-17 19:32:16 +08:00
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
//测试QQtDictionary的打印能力
|
|
|
|
|
QQtDictionary v00;
|
2018-04-18 00:16:29 +08:00
|
|
|
|
pline() << v00;
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary v0 ( "This is a value" );
|
2018-04-18 00:16:29 +08:00
|
|
|
|
pline() << v0;
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary v1;
|
2018-06-13 12:14:37 +08:00
|
|
|
|
v1.addChild ( "CCCC" );
|
|
|
|
|
v1.addChild ( "DDDD" );
|
|
|
|
|
v1[0].addChild ( "2-CCCC" );
|
2018-04-18 00:16:29 +08:00
|
|
|
|
pline() << v1;
|
|
|
|
|
pline() << v1[0];
|
|
|
|
|
|
2018-04-26 16:37:54 +08:00
|
|
|
|
QQtDictionary v2;
|
2018-04-18 00:16:29 +08:00
|
|
|
|
v2["AAAA"] = "NNNN";
|
|
|
|
|
v2["BBBB"] = "MMMM";
|
|
|
|
|
pline() << v2;
|
2018-01-21 21:48:02 +08:00
|
|
|
|
return 0;//a.exec();
|
|
|
|
|
}
|