本文整理汇总了C++中TestObject::setObjectName方法的典型用法代码示例。如果您正苦于以下问题:C++ TestObject::setObjectName方法的具体用法?C++ TestObject::setObjectName怎么用?C++ TestObject::setObjectName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestObject
的用法示例。
在下文中一共展示了TestObject::setObjectName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
try {
qlua::LuaContext ctx;
TestObject myobj;
myobj.setObjectName( "MyObject" );
//only add a single method to the Lua table
ctx.AddQObject( &myobj, "myobj", false,
qlua::LuaContext::QOBJ_NO_DELETE, qlua::LuaDefaultSignatureMapper(),
QStringList() << "emitSignal" );
ctx.Eval( "qlua.connect( myobj, 'aSignal(QString)', "
"function(msg) print( 'Lua callback called with data: ' .. msg ); end );"
"print( 'object name: ' .. myobj.objectName );"
"qlua.connect( myobj, 'aSignal(QString)', myobj, 'aSlot(QString)' );"
"myobj.emitSignal('hello')" );
TestObject* myobj2 = new TestObject;
QPointer< TestObject > pMyObject2 = myobj2;
myobj2->setObjectName( "MyObject2" );
ctx.AddQObject( myobj2, "myobj2", false, qlua::LuaContext::QOBJ_IMMEDIATE_DELETE );
ctx.Eval( "print( 'object 2 name: '..myobj2.objectName )" );
ctx.Eval( "myobj2=nil;collectgarbage('collect')");
if( pMyObject2.isNull() ) std::cout << "Object 2 garbage collected by Lua" << std::endl;
else std::cerr << "Object 2 not garbage collected!" << std::endl;
TestObject myobj3;
ctx.AddQObject( &myobj3, "myobj3", false, qlua::LuaContext::QOBJ_NO_DELETE );
ctx.Eval( "print( myobj3.copyString( 'hi' ) );"
"vm = myobj3.copyVariantMap( {key1=1,key2='hello'} );"
"print( vm['key1'] .. ' ' .. vm['key2'] );"
"print( myobj3.createObject().objectName );" );
ctx.Eval( "fl = myobj3.copyShortList( {1,2,3} );\n"
"print( fl[1] .. ' ' .. fl[ 3 ] );\n" );
} catch( const std::exception& e ) {
std::cerr << e.what() << std::endl;
}
return 0;
}
示例2: testDeregisterObjects
void TestWebChannel::testDeregisterObjects()
{
QWebChannel channel;
TestObject testObject;
testObject.setObjectName("myTestObject");
channel.registerObject(testObject.objectName(), &testObject);
channel.connectTo(m_dummyTransport);
channel.d_func()->publisher->initializeClient(m_dummyTransport);
QJsonObject connectMessage =
QJsonDocument::fromJson(("{\"type\": 7,"
"\"object\": \"myTestObject\","
"\"signal\": " + QString::number(testObject.metaObject()->indexOfSignal("sig1()"))
+ "}").toLatin1()).object();
channel.d_func()->publisher->handleMessage(connectMessage, m_dummyTransport);
emit testObject.sig1();
channel.deregisterObject(&testObject);
emit testObject.sig1();
}
示例3: testInfoForObject
void TestWebChannel::testInfoForObject()
{
TestObject obj;
obj.setObjectName("myTestObject");
QWebChannel channel;
const QJsonObject info = channel.d_func()->publisher->classInfoForObject(&obj, m_dummyTransport);
QCOMPARE(info.keys(), QStringList() << "enums" << "methods" << "properties" << "signals");
{ // enums
QJsonObject fooEnum;
fooEnum["Asdf"] = TestObject::Asdf;
fooEnum["Bar"] = TestObject::Bar;
QJsonObject expected;
expected["Foo"] = fooEnum;
QCOMPARE(info["enums"].toObject(), expected);
}
{ // methods & slots
QJsonArray expected;
{
QJsonArray method;
method.append(QStringLiteral("deleteLater"));
method.append(obj.metaObject()->indexOfMethod("deleteLater()"));
expected.append(method);
}
{
QJsonArray method;
method.append(QStringLiteral("slot1"));
method.append(obj.metaObject()->indexOfMethod("slot1()"));
expected.append(method);
}
{
QJsonArray method;
method.append(QStringLiteral("slot2"));
method.append(obj.metaObject()->indexOfMethod("slot2(QString)"));
expected.append(method);
}
{
QJsonArray method;
method.append(QStringLiteral("method1"));
method.append(obj.metaObject()->indexOfMethod("method1()"));
expected.append(method);
}
QCOMPARE(info["methods"].toArray(), expected);
}
{ // signals
QJsonArray expected;
{
QJsonArray signal;
signal.append(QStringLiteral("destroyed"));
signal.append(obj.metaObject()->indexOfMethod("destroyed(QObject*)"));
expected.append(signal);
}
{
QJsonArray signal;
signal.append(QStringLiteral("sig1"));
signal.append(obj.metaObject()->indexOfMethod("sig1()"));
expected.append(signal);
}
{
QJsonArray signal;
signal.append(QStringLiteral("sig2"));
signal.append(obj.metaObject()->indexOfMethod("sig2(QString)"));
expected.append(signal);
}
QCOMPARE(info["signals"].toArray(), expected);
}
{ // properties
QJsonArray expected;
{
QJsonArray property;
property.append(obj.metaObject()->indexOfProperty("objectName"));
property.append(QStringLiteral("objectName"));
{
QJsonArray signal;
signal.append(1);
signal.append(obj.metaObject()->indexOfMethod("objectNameChanged(QString)"));
property.append(signal);
}
property.append(obj.objectName());
expected.append(property);
}
{
QJsonArray property;
property.append(obj.metaObject()->indexOfProperty("foo"));
property.append(QStringLiteral("foo"));
{
QJsonArray signal;
property.append(signal);
}
property.append(obj.foo());
expected.append(property);
}
{
QJsonArray property;
property.append(obj.metaObject()->indexOfProperty("asdf"));
//.........这里部分代码省略.........