Qt framework related
Qt framework related
In one of my QML applications I’ve faced with a need to render one of the QML window (A) inside another one (B) while keeping the window A to be visible – kind of a live thumbnailing. There are some tools within Qt framework to achieve this, e.g. QQuickItem::grabToImage or use of QQuickRenderControl, but they are slow and cumbersome. So I’ve developed my own technique called “Portal” – a reference to famous “Portal” game where you could open a wormholes to desired areas and see these areas through.
qmake can generate Makefile either for dynamic or static version of a library by using CONFIG directive in .pro file:
|CONFIG += shared||Dynamic (shared) version (.so) of a library will be generated|
|CONFIG += staticlib||Static version (.a) of a library will be generated|
However one cannot mix these two directives and force this way qmake to generate both versions. This makes troubles when developing a library which must support both types of linking in a final application. Luckily I’ve found an easy workaround.
Avahi allows your program to advertise its services over the network via DNS-SD protocol. Other programs which use DNS-SD protocol will be able to discover advertised services and use them. No manual configuration is needed everything happens automatically, hence the name – Zeroconf. Let’s see how to properly write advertising Avahi client which is built on top of Qt framework.
When using a task manager in my QML applications I found that sometimes there is a need to postpone execution of next task until occurrence of some events. This could be the case when your application shows some notification and must go on with further processing only after user dismisses this notification. To support such scenarios task manager was extended as described below.
Smooth and responsive UI which keeps nice animation even when your program performs heavy duties. This is not “a nice to have” feature but an essential and “a must have” feature of your program if it is positioned as professionally made product. However following official guides for building Qt / QML applications won’t automatically deliver this feature. One can find some ideas how to get it in http://doc.qt.digia.com/qq/qq27-responsive-guis.html but it’s hard to adopt these ideas in large programs – too much manual work and it scales poorly. Good news that there is a complete, simple and easy way to get desired feature. Jump under the cut if you need some…
I’ve always been confused when used QByteArray::resize method. What will happen if memory allocation request would fail? Current Qt documentation (version 5.4 at the moment of writing) doesn’t say anything. Keeping in mind that Qt doesn’t honor exceptions I’ve believed than in case of memory outage Qt will simply leave my QByteArray object at its present state. So I’ve used code like this:
const int newBufferSize = buffer.size() * 2;
if(buffer.size() < newBufferSize)
// ... handle realloc failure somehow
However I was mistaken. Qt will simply… raise std::bad_alloc exception in case of memory outage. Sample program which demonstrates this is here: svn co https://github.com/kocherovms/develorium.com/trunk/qbytearray_resize.
Throwing exception is a normal C++ practice (and I like it), but that’s completely unexpected from Qt which avoids exceptions as much as possible. I’ve posted but QTBUG-44900, hope documentation will be fixed soon.
Another interesting unexpected behavior is mentioned in QTBUG-33037. Be careful!
Consider QML application where UI has non-stop animation, e.g. video is playing in the background or slides are floating around slowly. Source code of prototype of such application: svn co https://github.com/kocherovms/develorium.com/trunk/async_db_ops_in_qml_apps/0
Application’s data is stored in database and it’s necessary to implement ordinary function: full text search against this database. So, how do you do that while keeping responsive UI?