Details
Description
Porting existing application with QMessageBox
and other QDialog derivatives where sizes were not set explicitly
but instead were guessed and set by Qt, results in application
being stacked, crashing, etc. weird behaviour when the dialog started
with modality flag set.
qt-everywhere-opensource-src-5.1.0.tar.gz release
configured as:
./configure -developer-build -xplatform android-g++ -nomake tests -nomake examples -android-ndk /home/robert/dev/android-ndk-r8e-ma -android-sdk /home/robert/dev/android-sdk-linux -android-ndk-host linux-x86 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples
To reproduce comment out the line with resize() in mainwindow.cpp
The workaround is to set the sizes of the dialog.
However, it's a really bad option since for
every dialog and depending on display, fonts, etc
One more issue is that modal dialogs are not
centered above the parent window, true for the Android port
and API-16, 17
---------------main.cpp ------------
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.resize(600, 300);
w.show();
return a.exec();
}
------------------------------------
-----------mainwindow.h--------------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QMessageBox>
#include <QTimer>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
virtual void showEvent (QShowEvent * event);
private slots:
void show_dialog();
private:
//QMessageBox message_box_;
QTimer init_timer_;
bool is_shown_;
};
#endif // MAINWINDOW_H
------------------------------------
-----------mainwindow.cpp---------
#include <QShowEvent>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
init_timer_(this),
is_shown_(false)
{
}
MainWindow::~MainWindow()
{
}
//virtual
void MainWindow::showEvent (QShowEvent * event)
{
QMainWindow::showEvent( event );
if( event->spontaneous() )
return;
if(this->is_shown_) // init is_shown_ to 'false' in constructor
return;
else
this->is_shown_ = true;
// init stuff
this->init_timer_.setInterval(10*1000); // 1000 msec
connect(&this->init_timer_, SIGNAL(timeout()), SLOT(show_dialog()));
this->init_timer_.start();
}
// private slot
void MainWindow::show_dialog()
{
this->init_timer_.stop();
QMessageBox msgBox(this);
//msgBox.resize(200, 100);
msgBox.setWindowModality(Qt::WindowModal);
msgBox.setText("The Dialog");
msgBox.exec();
}