Vinayak Garg
Vinayak Garg

Reputation: 6606

Qt Application using C++ and QML

I am new to Qt, and am using Qt Creator 2.4.1 for development.

Question - Where can I find (or What are the) examples built using QML and C++?

I have been searching and its been not very fruitful. Like I have found examples using pure QML. Or the demo "samegame" uses javascript with QML.

Just to try out, here is some code I wrote in main.cpp -

QDeclarativeView view;
view.rootContext()->setContextProperty("game", new Game);
view.setSource(QUrl("qml/hangman/main.qml"));

view.show();

The question related to code - If I were to use C++ and QML, is this how the code in main() is supposed to be?

In the main.qml I will make all the different types of buttons, and mouseareas required.

Upvotes: 1

Views: 1330

Answers (1)

aleks_misyuk
aleks_misyuk

Reputation: 577

Here's examples from Qt documentation. You may see C++ code in most examples.
Usually, the main function is as below:

 QApplication app(argc, argv);

 QmlApplicationViewer viewer;
 viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
 viewer.setMainQmlFile(QLatin1String("path_to_qml"));
 viewer.showExpanded();

 return app.exec();

Extending QML Functionalities using C++ is good article too.

Upvotes: 2

Related Questions