PDA

View Full Version : Android: QDialog becomes invisible when adding QML component (QQuickWidget) to it



alecs1
8th March 2015, 11:27
In a Widgets application I want to show a modal dialog designed with QML.

I chose to create a QDialog and insert the QML component inside it. This works well on desktop, but leads to an invisible window on Android. When showing the QDialog with a QPushButton it works as expected, but when I add a QQuickWidget to it, the QDialog becomes invisible.

The mouse area _does_ react to clicks and when I print the sizes at various steps they seem fine. Also, when rotating the device or bringing the app to front, I get to see a glimpse of the QDialog window and it seems to look as expected.


C++ file:


AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) {
if (layout() != NULL)
delete layout();
QGridLayout* gridLayout= new QGridLayout();
setLayout(gridLayout);

okButton = new QPushButton("Close", this);
gridLayout->addWidget(okButton, 1, 0);

quickWidget = new QQuickWidget();
quickWidget->setSource(QUrl("qrc:/Example.qml"));
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
quickWidget->resize(100, 100);

gridLayout->addWidget(quickWidget, 0, 0);

resize(800, 800);
}

Header file:


class AboutDialog : public QDialog {
public:
AboutDialog(QWidget* parent=0);

private:
QQuickWidget* quickWidget = NULL;
QPushButton* okButton;
};


QML file:


import QtQuick 2.0

Rectangle {
width: 700
height: 700

color: "#000000"

Rectangle {
height: 600
anchors.left: parent.left; anchors.right: parent.right
anchors.leftMargin: 30; anchors.rightMargin: 30
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
color: "#dd0000"

Text {
anchors.centerIn: parent
font.pixelSize: 30
text: "Quit"
color: "#e0e0e0"
}

MouseArea {
anchors.fill: parent
onClicked: Qt.quit();
}
}
}

Added after 14 minutes:

Adb logcat of what seemed relevant (happens on all 3 device I tried with):


#Trigger showing the window, FreeGo is the name of the App.

D/FreeGo ( 8885): void GameSettings::showMenu()
W/libFreeGo.so( 8885): (null):0 ((null)): This plugin does not support grabbing the keyboard
E/Parcel ( 440): Reading a NULL string not supported here.
E/Parcel ( 440): Reading a NULL string not supported here.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 500 ms
W/qdhwcomposer( 318): Excessive delay reading vsync: took 216 ms
D/FreeGo ( 8885): AboutDialog::AboutDialog(QWidget*)
D/FreeGo ( 8885): AboutDialog::AboutDialog(QWidget*) - sizes: window: (0 0) 800x800;
D/FreeGo ( 8885): quickWidget:(0 0) 100x100
D/FreeGo ( 8885): virtual int AboutDialog::exec() - sizes: window: (0 0) 800x800;
D/FreeGo ( 8885): quickWidget:(0 0) 100x100
D/FreeGo ( 8885): virtual void AboutDialog::resizeEvent(QResizeEvent*) - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
D/FreeGo ( 8885): virtual void AboutDialog::resizeEvent(QResizeEvent*) - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
W/Adreno-EGL( 8885): <qeglDrvAPI_eglSwapInterval:3818>: EGL_BAD_SURFACE
W/Adreno-EGL( 8885): <qeglDrvAPI_eglSwapInterval:3818>: EGL_BAD_SURFACE
W/qdhwcomposer( 318): Excessive delay reading vsync: took 83 ms
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 300 ms
W/qdhwcomposer( 318): Excessive delay reading vsync: took 1401 ms


#Press the back button here:

D/FreeGo ( 8885): virtual int AboutDialog::exec() - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
D/FreeGo ( 8885): virtual int AboutDialog::exec() - retVal=0
D/FreeGo ( 8885): virtual AboutDialog::~AboutDialog() - sizes: window: (487 62) 800x800;
D/FreeGo ( 8885): quickWidget:(24 24) 752x595
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
W/qdhwcomposer( 318): Excessive delay reading vsync: took 38 ms
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
W/libFreeGo.so( 8885): (null):0 ((null)): Can't find surface 4
W/WindowManager( 854): Access to extended visibility flags denied: Requires com.sonymobile.permission.SYSTEM_UI_VISIBILITY_EXT ENSIONS permission.
E/Parcel ( 440): Reading a NULL string not supported here.

anda_skoa
8th March 2015, 12:13
You could try a QQuickWindow instead of the QDialog.

A simple subclass with an exec() like method that sets the modality of the window, shows it and executes a nested event loop.

Cheers,
_

alecs1
8th March 2015, 15:23
Same behaviour with QQuickView. I tried it like this:



QQuickView* view = new QQuickView();
view->setSource(QUrl("qrc:/Example.qml"));
view->show();


However, I noticed on the older phone that if I press home and then bring the program back to front with the task manager, then the QDialog/QQuickView will actually display and stay there for good. On the newer phone it only show for a fraction of a second.

Apart from the code, are there other important parts I may be missing? Like AndroidManifest.xml or project flags? If of any use, I could upload short movie somewhere. and the entire code is online at https://github.com/alecs1/home/tree/master/qt/qtgo/qtgo.

anda_skoa
9th March 2015, 09:01
Sorry, no further idea.
It could be a limiation of the Android integration, i.e. the mixing of OpenGL and non-OpenGL rendering.

Cheers,
_

alecs1
9th March 2015, 18:03
Thanks, I'll reach for Digia with this question and 1-2 widgets bugs on Android.