int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); qmlRegisterType<Window>("People", 1, 0, "Window"); qmlRegisterType<Person>("People", 1, 0, "Person"); QQmlApplicationEngine engine; QQmlComponent *component = new QQmlComponent(&engine); QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); component->loadUrl(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *appWindow = component->create(); //these three lines are simply to show that we can change the name value //of this QObject *persona = appWindow->findChild<QObject*>("persona"); if (persona) persona->setProperty("name", "Blanco"); //these three lines are simply to show that we can change the text value //of this (comment or uncomment these lines to see that we can change any //property in the qml from c++ code /* QObject *label = appWindow->findChild<QObject*>("label"); if (label) label->setProperty("text", QString("Ramon (changed from c++ code)")); */ QQuickWindow *window = qobject_cast<QQuickWindow *>(appWindow); QSurfaceFormat surfaceFormat = window->requestedFormat(); window->setFormat(surfaceFormat); window->show(); return app.exec(); }
this->m_convert->setProperty("caps", "video/x-raw,format=bgra"); this->resetAmplitude(); this->resetFrequency(); this->resetGridSizeLog(); } QObject *DistortElement::controlInterface(QQmlEngine *engine, const QString &controlId) const { Q_UNUSED(controlId) if (!engine) return NULL; // Load the UI from the plugin. QQmlComponent component(engine, QUrl(QStringLiteral("qrc:/Distort/share/qml/main.qml"))); // Create a context for the plugin. QQmlContext *context = new QQmlContext(engine->rootContext()); context->setContextProperty("Distort", (QObject *) this); context->setContextProperty("controlId", this->objectName()); // Create an item with the plugin context. QObject *item = component.create(context); context->setParent(item); return item; } qreal DistortElement::amplitude() const {
void TestSimpleQmlLoad::loadAlias4() { QVariant v; QQmlEngine *engine = new QQmlEngine; const QString TEST_FILE(":/testqml/testalias4.qml"); QQmlComponent* component = load(engine, TEST_FILE); QVERIFY(component); QObject *myObject = component->create(); QVERIFY(myObject != NULL); // check that the alias's work v = myObject->property("i1_x"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 111); v = myObject->property("i1_x"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 111); QObject *i2 = myObject->findChild<QObject*>("i2"); v = i2->property("i1_x"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 111); v = myObject->property("r0_height"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 222); v = i2->property("r0_height"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 222); // change the aliases target values and check again. QObject *i1 = myObject->findChild<QObject*>("i1"); QVERIFY(i1); i1->setProperty("x", 666); v = myObject->property("i1_x"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 666); v = i2->property("i1_x"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 666); QObject *r0 = myObject->findChild<QObject*>("r0"); QVERIFY(r0); r0->setProperty("height", 777); v = myObject->property("r0_height"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 777); v = i2->property("r0_height"); QVERIFY(!v.isNull()); QVERIFY(v.toInt() == 777); delete component; delete engine; }