本文整理汇总了C++中ObjectRef::setProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectRef::setProperty方法的具体用法?C++ ObjectRef::setProperty怎么用?C++ ObjectRef::setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectRef
的用法示例。
在下文中一共展示了ObjectRef::setProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void DesktopConfigDbBackend::init()
{
m_manager->reset();
m_currentOid = 1;
//KSimpleConfig config( m_fileName ); // DEPRECATED KDE3 -> KDE4 by Percy
KConfig config( m_fileName );
QStringList groups = config.groupList();
QStringList::ConstIterator it( groups.begin() );
QStringList::ConstIterator end( groups.end() );
QMap<QString,QString> map;
for ( ; it != end; ++it ) {
map = config.entryMap( *it );
ObjectRef<Object> obj;
if ( map.contains( "oid" ) )
obj = Classes::classInfo( *it )->create( stringToOid( map["oid"] ), m_manager, true );
else
obj = Classes::classInfo( *it )->create( m_manager );
assert( obj );
if ( m_currentOid < obj->oid() )
m_currentOid = obj->oid();
//QMapConstIterator<QString,QString> mit( map.begin() ); // DEPRECATED Qt3 -> Qt4 by Percy
//QMapConstIterator<QString,QString> mend( map.end() ); // DEPRECATED Qt3 -> Qt4 by Percy
QMap<QString, QString>::const_iterator mit( map.begin() );
QMap<QString, QString>::const_iterator mend( map.end() );
for ( ; mit != mend; ++mit ) {
if ( mit.key() != "oid" )
//obj->setProperty( mit.key(), mit.data() ); // DEPRECATED Qt3 -> Qt4 by Percy
obj->setProperty( mit.key().toAscii(), QVariant(mit.value()) );
}
}
}
示例2: allTests
void DynamicObjectsTest::allTests()
{
QString dbname = "testdynamic";
Classes::setup();
Classes::addClass( "Test", DynamicObject::createInstance, 0 );
ClassInfo *ci = Classes::classInfo( "Test" );
ci->addObject( "Customer", "Customer_Test", &Customer::createInstance );
ci->addCollection( "Article", "Article_Test" );
PropertyInfo *p;
p = new PropertyInfo();
p->setName( "Property1" );
p->setType( QVariant::String );
ci->addProperty( p );
p = new PropertyInfo();
p->setName( "Property2" );
p->setType( QVariant::ULongLong );
ci->addProperty( p );
Classes::setupRelations();
// Drop the database if already exists
KProcess *proc = new KProcess;
*proc << "dropdb";
*proc << dbname;
proc->start();
proc->wait();
delete proc;
// Create the database
proc = new KProcess;
*proc << "createdb";
*proc << dbname;
CHECK( proc->start(), true );
proc->wait();
if ( ! proc->normalExit() || proc->exitStatus() != 0 ) {
CHECK( true, false );
delete proc;
return;
}
delete proc;
QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" );
db->setDatabaseName( dbname );
db->setUserName( "ak213" );
db->setPassword( "ak" );
db->setHostName( "localhost" );
if ( ! db->open() ) {
kdDebug() << "Failed to open database: " << db->lastError().text() << endl;
return;
}
DbBackendIface *backend = new SqlDbBackend( db );
m_manager = new Manager( backend );
m_manager->setMaxObjects( 1 );
m_manager->createSchema();
ObjectRef<Customer> customer = Customer::create();
customer->setCustomerName( "Name of the customer" );
ObjectRef<Article> a1 = Article::create();
a1->setCode( "00001" );
ObjectRef<Article> a2 = Article::create();
a2->setCode( "00002" );
ObjectRef<Object> obj = Classes::classInfo( "Test" )->create();
CHECK( obj->property( "Property1" ).type(), QVariant::String );
CHECK( obj->property( "Property2" ).type(), QVariant::ULongLong );
CHECK( obj->containsObject( "Customer_Test" ), true );
CHECK( obj->containsCollection( "Article_Test" ), true );
obj->setProperty( "Property1", "Property number one" );
obj->setProperty( "Property2", 2 );
CHECK( obj->property( QString( "Property1" ) ).value().toString(), QString( "Property number one" ) );
CHECK( obj->property( QString( "Property2" ) ).value().toULongLong(), 2 );
obj->setObject( "Customer_Test", customer );
obj->collection( "Article_Test" )->add( a1 );
obj->collection( "Article_Test" )->add( a2 );
m_manager->commit();
CHECK( obj->property( "Property1" ).value().toString(), QString( "Property number one" ) );
delete m_manager;
}