Home > Enterprise >  Qt Android blank window
Qt Android blank window

Time:08-16

Problem

I have a problem with Qt on Android in all my applications: after I close the QFileDialog (code below), I have a blank black window. I can't do anything in the application except close it.
Here is the code I use:

QFileDialog dialog(this, tr("Open Markdown File"));
dialog.setMimeTypeFilters({"text/markdown"});
dialog.setAcceptMode(QFileDialog::AcceptOpen);
if (dialog.exec() == QDialog::Accepted) {
    const QString file = dialog.selectedFiles().at(0);
    if (file == path || file.isEmpty()) return;
    openFile(file);
}

Informations

  • My Qt version is Qt 6.2.4
  • Device running on: Samsung Galaxy S10e
  • arm64-v8 build
  • JDK version 17
  • SDK-Version: 7.0
  • NDK-Version: 22.1.7171670
  • C version 17

Edit

Here a Screenshot what I see: What I see

Edit 2

After some more debugging i figured out, that it reaches the end of the code. I also tried to add Q[Core|Gui]Application::processEvents() and QMainWindow::repaint() but i istill have the blank screen as you cas see in the screenshot above.

Edit 3

The Code is in a QMainWindow and is executed in the main thread. The APP has a QApplication object. After the end of the code is reached, the main thread aka main event loop runs as usual, but I have a black window.

You can find all the code on GitHub, but only the part I showed causes problems.

CodePudding user response:

Works well on my configuration:

  • Samsung Note 20, Android 12, latest update,
  • Qt 6.3.1, clang arm64-v8a, enter image description here
  • SDK 7.0, NDK 22.1.7171670. enter image description here

Demo: https://youtube.com/shorts/KkyrTYkTNb0?feature=share. Your app open and save file well, FileDialog works well too. So no assumptions about the reasons you see blank screen: may be phone software version, may be some feature of your Qt version.

I did several changes in your project however to be able to read and write files on android:

  1. Created Android build files enter image description here
  2. Added READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions to manifest. enter image description here
  3. Added setDirectWriteFallback(true) to mainwindow.cpp:
1139:    QSaveFile f(path, this);
1140:    f.setDirectWriteFallback(true); //!!!
1141:    if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
         ...

otherwise file created, but I had an error on f.commit(): enter image description here

  • Related