I've found the way to get the QML output as QImage, but it works only if the QML window has focus. Incomplete code snippet follows:
QApplication app(argc, argv);
QQmalApplicationEngine *appEngine = new QQmlApplicationEngine(this);
appEngine->load(script_path);
...
app.exec();
While app is running, you can grab window contents like this:
QQuickWindow *win = qobject_cast<QQuickWindow *>(appEngine->rootObjects().first());
QImage grabbed = win->grabWindow();
It has several drawbacks (i.e. cursor disappears when the input focus is lost, grabWindow() is very slow etc.).
Furthermore, it's also possible to redirect QML page rendering to a custom FBO, this provides a much faster solution but also suffers from some issues.