Questions & Answers from Qt for Beginners Part 4 - Doing More

Questions & Answers from Qt for Beginners Part 4 - Doing More

By Christopher Probst

Download the entire webinar series.

What's the best approach for doing webscraping in Qt now that QtWebkit has been deprecated?

QtWebEngine is the replacement for QtWebKit and provides similar functionality. Webscraping generally refers to grabbing web pages and extracting content from them, but not rendering them. You should be able to do this with the Qt Network module, pulling the relevant web pages from a server and then parsing the received HTML using string and/or regular expression classes. Finally, if you really need QtWebKit, some people are discussing unofficially continuing to maintain it. See the Qt mailing lists for the current status.

Do all the "import QtQuick" statements in different QML files need to refer to same version?

No, you can safely import different versions in different QML files. Some developers may choose to keep all their imports at the same version for consistency. Others update the version only when they need an API from a newer version.

Can I create all widgets for desktop application using QML?

While it is possible to combine widgets and QML, you can't create true widgets directly from QML. But the Qt Quick Controls provide QML equivalents to many of the desktop widgets, so you can create a QML application that has a desktop look and feel in this way.

Does ICS plan to present a webinar that goes into detail on embedded developement in Qt Creator, and deploying to remote devices?

That is a good suggestion and we will consider it. A low cost board like Raspberry Pi or Beaglebone black would probably be a good example to use for the embedded platform.

In the example of exposing a C++ variable using the context engine, the type itself is also registered. Is this necessary if all you are doing is registering a context property?

You do not need to register the type if you are not going to create new instances of the object in your QML.

Is it okay to use x,y coordinates instead of layouts in QML screen development?

In general, layouts are better so that the code is more readable, easier to modify, and can support localization. If you have a good reason for using x, y coordinates, you can do so.

Is there a time where I should use QQmlApplicationEngine rootContext setContextProperty instead of qmlRegisterType in order to expose C++ objects in QML?

You want to use setContextProperty when you want a predefined object available to reference in your QML and aren't interested in the ability to make new instances of the object.

When there is an error in QML Qt does not exit. How can I exit?

If you mean an error, such as a syntax error, when the QML code is being interpreted or just in time compiled, that seems to be hard to detect since the load() method does not return any status. You might be able to look at any errors or warnings output. 

Are there plans for a Python plugin in Qt Creator for PySide development?

I believe that Qt Creator supports Python for code editing but I don't know if there are any plans for additional support. This has been suggested in the past. You could ask on the relevant mailing list: http://lists.qt-project.org/mailman/listinfo/qt-creator

Is there a way in Qt to support dynamic translation without requiring the ts file to be part of the source but be made at run time?

ts files are normally converted (using the lrelease tool) to qm files and read at run-time. They can be external files, so they don't have to be compiled into your application. If you could provide translations as qm files, your application could load them dynamically.

What are the short cut key(s) to zoom text in the editor within Qt Creator?

<Control>+ and <Control>- or <Control><Mouse Scroll Wheel>