本文整理汇总了C++中QDeclarativeContext::setObjectName方法的典型用法代码示例。如果您正苦于以下问题:C++ QDeclarativeContext::setObjectName方法的具体用法?C++ QDeclarativeContext::setObjectName怎么用?C++ QDeclarativeContext::setObjectName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDeclarativeContext
的用法示例。
在下文中一共展示了QDeclarativeContext::setObjectName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initTestCase
void tst_QDeclarativeDebug::initTestCase()
{
qRegisterMetaType<QDeclarativeDebugWatch::State>();
QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3768...");
qputenv("QML_DEBUG_SERVER_PORT", "3768");
m_engine = new QDeclarativeEngine(this);
QList<QByteArray> qml;
qml << "import Qt 4.7\n"
"Item {"
"width: 10; height: 20; scale: blueRect.scale;"
"Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }"
"Text { color: blueRect.color; }"
"MouseArea {"
"onEntered: { console.log('hello') }"
"}"
"}";
// add second component to test multiple root contexts
qml << "import Qt 4.7\n"
"Item {}";
// and a third to test methods
qml << "import Qt 4.7\n"
"Item {"
"function myMethodNoArgs() { return 3; }\n"
"function myMethod(a) { return a + 9; }\n"
"function myMethodIndirect() { myMethod(3); }\n"
"}";
for (int i=0; i<qml.count(); i++) {
QDeclarativeComponent component(m_engine);
component.setData(qml[i], QUrl::fromLocalFile(""));
Q_ASSERT(component.isReady()); // fails if bad syntax
m_components << qobject_cast<QDeclarativeItem*>(component.create());
}
m_rootItem = qobject_cast<QDeclarativeItem*>(m_components.first());
// add an extra context to test for multiple contexts
QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this);
context->setObjectName("tst_QDeclarativeDebug_childContext");
m_conn = new QDeclarativeDebugConnection(this);
m_conn->connectToHost("127.0.0.1", 3768);
QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
bool ok = m_conn->waitForConnected();
Q_ASSERT(ok);
QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
m_dbg = new QDeclarativeEngineDebug(m_conn, this);
}
示例2: initTestCase
void tst_QDeclarativeDebug::initTestCase()
{
qRegisterMetaType<QDeclarativeDebugWatch::State>();
qmlRegisterType<NonScriptProperty>("Test", 1, 0, "NonScriptPropertyElement");
QTest::ignoreMessage(QtDebugMsg, "QDeclarativeDebugServer: Waiting for connection on port 3768...");
m_engine = new QDeclarativeEngine(this);
QList<QByteArray> qml;
qml << "import QtQuick 1.0\n"
"import Test 1.0\n"
"Item {"
"id: root\n"
"width: 10; height: 20; scale: blueRect.scale;"
"Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }"
"Text { color: blueRect.color; }"
"MouseArea {"
"onEntered: { console.log('hello') }"
"}"
"property variant varObj\n"
"property variant varObjList: []\n"
"Component.onCompleted: {\n"
"varObj = blueRect;\n"
"var list = varObjList;\n"
"list[0] = blueRect;\n"
"varObjList = list;\n"
"}\n"
"NonScriptPropertyElement {\n"
"}\n"
"}";
// add second component to test multiple root contexts
qml << "import QtQuick 1.0\n"
"Item {}";
// and a third to test methods
qml << "import QtQuick 1.0\n"
"Item {"
"function myMethodNoArgs() { return 3; }\n"
"function myMethod(a) { return a + 9; }\n"
"function myMethodIndirect() { myMethod(3); }\n"
"}";
// and a fourth to test states
qml << "import QtQuick 1.0\n"
"Rectangle {\n"
"id:rootRect\n"
"width:100\n"
"states: [\n"
"State {\n"
"name:\"state1\"\n"
"PropertyChanges {\n"
"target:rootRect\n"
"width:200\n"
"}\n"
"}\n"
"]\n"
"transitions: [\n"
"Transition {\n"
"from:\"*\"\n"
"to:\"state1\"\n"
"PropertyAnimation {\n"
"target:rootRect\n"
"property:\"width\"\n"
"duration:100\n"
"}\n"
"}\n"
"]\n"
"}\n"
;
for (int i=0; i<qml.count(); i++) {
QDeclarativeComponent component(m_engine);
component.setData(qml[i], QUrl::fromLocalFile(""));
QVERIFY(component.isReady()); // fails if bad syntax
m_components << qobject_cast<QDeclarativeItem*>(component.create());
}
m_rootItem = qobject_cast<QDeclarativeItem*>(m_components.first());
// add an extra context to test for multiple contexts
QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this);
context->setObjectName("tst_QDeclarativeDebug_childContext");
m_conn = new QDeclarativeDebugConnection(this);
m_conn->connectToHost("127.0.0.1", 3768);
QTest::ignoreMessage(QtDebugMsg, "QDeclarativeDebugServer: Connection established");
bool ok = m_conn->waitForConnected();
QVERIFY(ok);
QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
m_dbg = new QDeclarativeEngineDebug(m_conn, this);
QTRY_VERIFY(m_dbg->status() == QDeclarativeEngineDebug::Enabled);
}