2

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.

Tim
  • 406
  • 3
  • 14
  • 3
    Note that using QML (Qt Quick) may be the better option to create a mobile app. – m7913d Aug 09 '22 at 12:51
  • Unfortunately I have no QML experience, but I wanted to try it out soon. The APP is also actually a desktop app, but I wanted to get them to run on mobile (Wasm works). – Tim Aug 09 '22 at 13:20
  • Is there a main window for this program? Otherwise it is unclear where the execution supposed to return to on UI thread. Make sure there is QApplication object in the context of which you have QMainWindow or the other widget as main and that launches the dialog. In case if you only have one dialog it seems you need to explicitly quit the app then. Not even exactly Android problem but the context. Where the UI thread is running after closing the dialog? What window is handling that to paint its background on the screen? How is it possible to answer with your limited example above? – Alexander V Aug 10 '22 at 01:11
  • @AlexanderV: I edited the question but i dont think it helps – Tim Aug 10 '22 at 09:34
  • `#ifdef Q_OS_ANDROID // Prevent blank window a.processEvents(); #endif return a.exec();` Still something is wrong but need to run your project to realize. QApplication::exec() already does event processing so no other processEvents needed. – Alexander V Aug 10 '22 at 19:56
  • I thought so too. But without this code I just have a white window. – Tim Aug 10 '22 at 20:02
  • When started the program pause it with debugger and see the stack on UI thread. Where it ends? – Alexander V Aug 10 '22 at 20:02
  • Somehow the debugger doesn't work for me on Android. Unfortunately. – Tim Aug 10 '22 at 20:10
  • Verify the project is Native Activity type. Or that is what I remember from years ago. – Alexander V Aug 14 '22 at 22:22

1 Answers1

1

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

Ornstein89
  • 598
  • 1
  • 6
  • 15