Weird problem with setupUI call
-
bq. Mingw does not like the call to QMainWindow(parent)
This is definitely not true. This should work on all platforms as well as here.
Of the ui->setupUI(this) crash, the ui is propably not initialised. This you should see in your debugger.
I'm always use ui on all platforms (mac, unix, linux, windows mingw and windows msvc) and everything is working without platform definitions! -
Here's what I know. If I use the constructor specified in the else clause of the #if defined statement, I do not even enter the constructor function. If I use the one specified in the if (MINGW32) part, I do enter the constructor function. So, on my system, mingw does not seem to like the call to QMainWindow(parent).
If setupUi does not initialize the ui, then what does? Here's the code that calls the constructor:
@
void Init(int argc, char *argv[])
{
if (m_pgsdApp == NULL)
{
m_pgsdApp = new QApplication(argc, argv);
QSplashScreen *m_pSplash = new QSplashScreen;
m_pSplash->setPixmap(QPixmap(":/images/splash/gsDesignSplash.png"));
m_pSplash->show();Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
m_pSplash->showMessage(QObject::tr("Loading graphical user interface ... "),
topRight, Qt::white);int delay = 3500;
QTimer::singleShot(delay, m_pSplash, SLOT(close()));m_pgsdApp->processEvents();
m_gsdWindow = new gsDesign();
QTimer::singleShot(delay, m_gsdWindow, SLOT(show()));
}
}
@ -
Sure!
@
namespace Ui {
class gsDesign;
}class gsDesign : public QMainWindow {
Q_OBJECT
public:
gsDesign(QWidget *parent = 0);
~gsDesign();
enum Spending { LowerSpending, UpperSpending };
enum MapAction { setMap, getMap };protected:
void changeEvent(QEvent *e);
bool eventFilter(QObject *o, QEvent *e);private slots:
void populatePlotFromDesignQMap();
void fillAnalysisTable(double *array, int len);
bool validatePiecewiseTables();
bool isValidPiecewiseTable(QTableWidget *table, QSpinBox *spin, int *emptyIndex);
double convertEventRate(double val);
void dnDescCombo_returnPressed();
void dnNameCombo_returnPressed();
void on_menuActionAutoscalePlot_toggled(bool );
void quit();
void on_menuActionExit_triggered();
void on_opYLabelLeftLine_editingFinished();
void on_opXLabelLine_editingFinished();
void on_opTitleLine_editingFinished();
void on_opPlotRenderCombo_currentIndexChanged(int index);
void on_menuActionPlotDefaults_triggered();
void informationHandler(QString information);
void warningHandler(QString warning);
void errorHandler(QString error);
bool exportAllDesigns();
void on_menuActionExportAllDesigns_triggered();
void on_toolbarActionSetWorkingDirectory_triggered();
bool setWorkingDirectory();
void on_menuActionChangeWorkingDirectory_triggered();
void on_toolbarActionEditPlot_triggered();
void on_menuActionExportPlot_triggered();
void exportPlot();
void on_toolbarActionExportPlot_triggered();
QMap<QString, QString> updateDesignMap();
QString QComboBoxIndexToQString(QComboBox *combo);
QString QDoubleSpinBoxValueToQString(QwtCounter *dspin);
QString QSpinBoxValueToQString(QSpinBox *spin);
QString QTableWidgetToQString(QTableWidget *table);
QString strippedName(const QString &fullFileName);
bool exportDesign();
bool save();
bool saveAs();
bool saveFile(const QString &fileName);
bool writeFile(const QString &fileName);
void about();
void addNewDesign();
void contextHelp();
void deleteDesign();
void designMapToQComboBox(QComboBox *combo);
...
// QList of QMaps comprising design list
QList<QMap<QString, QString> > designList;
QMap<QString, QString> defaultDesign;// File I/O QString currentDesignFile; QString plotFilePath; QDir currentWorkingDirectory;
};
@ -
The constructor MUST look like this:
@
gsDesign::gsDesign(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::gsDesign)
{
printf("Can we make it here...n");
ui->setupUi(this);
printf("Maybe here...n");
@perhaps you should rename the UI class in the ui file:
@
namespace Ui {
class gsDesignUI;
}
@ -
Gerolf:
I reimplemented the constructor to look like what you posted. I also changed some slot/signal connectors based on trying to build this on a Mac (there were some on_xxx_valueChanged functions created and similar slot/signal connections defined in the .ui file. Linux did not warn and compiled and ran fine. Mac complained, but compiled and ran fine. Windows did not complain and compiled, but did not execute). When I made the change of removing the connections from the .ui file, I could then enter the constructor with the implementation you describe. I still cannot get past the call to setupUi.
Now, what would renaming the class get me?
Dave H
-
Here is the compilation and an example run. I decorated the code with some printf's to show what is being called when. I do not understand the problem with QApplication as it was created many lines before the error shows up...
Compilation messages:
@
dnadave@ecthgow-vm /c/Users/dnadave/workspace/GSDesignGUI/trunk/package
$ R CMD INSTALL --no-clean-on-error gsDesignExplorer- installing to library 'c:/Program Files/R/R-2.13.0/library'
- installing source package 'gsDesignExplorer' ...
** libs
running src/Makefile.win ...
mkdir -p ../explorergui-build;
cd ../explorergui-build;
CC="c:/rtools/mingw/bin/gcc.exe" CXX="c:/rtools/mingw/bin/g++.exe"
cmake -G "MSYS Makefiles" ../src -DR_LIBRARIES="-Lc:/PROGRA~1/R/R-213~1.
0/bin/i386 -lR -L../inst/libs/i386"
-DR_INCLUDES=c:/PROGRA~1/R/R-213~1.0/include -DCMAKE_INSTALL_PREFIX=../i
nst/libs/i386/;
make install;
cp ../inst/libs/i386/bin/*.dll ../inst/libs/i386;
rm -rf ../inst/libs/i386/bin;
cp -Ru ../src/images/ ../inst
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: c:/Rtools/MinGW/bin/gcc.exe
-- Check for working C compiler: c:/Rtools/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: c:/Rtools/MinGW/bin/g++.exe
-- Check for working CXX compiler: c:/Rtools/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - not found.
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - found
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found.
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found.
-- Found Qt-Version 4.7.3 (using c:/QtSDK/Desktop/Qt/4.7.3/mingw/bin/qmake.exe)
-- Found Qwt: C:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExplo
rer/inst/libs/i386/qwtd5.dll
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/dnadave/workspace/GSDesignGUI/trun
k/package/gsDesignExplorer/explorergui-build
[ 8%] Generating ui_gsdesign.h
[ 16%] Building CXX object CMakeFiles/gsDesignExplorer.dir/Rcpp.cpp.obj
[ 25%] Building CXX object CMakeFiles/gsDesignExplorer.dir/gsdesign.cpp.obj
[ 33%] Building CXX object CMakeFiles/gsDesignExplorer.dir/gsDesignGUI.cpp.obj
[ 41%] Building CXX object CMakeFiles/gsDesignExplorer.dir/gsDesignTips.cpp.obj
[ 50%] Building CXX object CMakeFiles/gsDesignExplorer.dir/GsRList.cpp.obj
[ 58%] Building CXX object CMakeFiles/gsDesignExplorer.dir/main.cpp.obj
c:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExplorer/src/main.c
pp:165:37: warning: unused parameter 'hModule'
c:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExplorer/src/main.c
pp:165:37: warning: unused parameter 'lpReserved'
[ 66%] Generating gsDesignExplorer.def
[ 75%] Generating moc_gsdesign.cxx
[ 83%] Generating qrc_images.cxx
Scanning dependencies of target gsDesignExplorer
[ 91%] Building CXX object CMakeFiles/gsDesignExplorer.dir/moc_gsdesign.cxx.obj
[100%] Building CXX object CMakeFiles/gsDesignExplorer.dir/qrc_images.cxx.obj
Linking CXX shared library libgsDesignExplorer.dll
Creating library file: libgsDesignExplorer.dll.a
[100%] Built target gsDesignExplorer
Install the project...
-- Install configuration: ""
-- Installing: C:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExpl
orer/inst/libs/i386/./libgsDesignExplorer.dll
@
Example run:
@
dnadave@ecthgow-vm ~
$ RR version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.library(gsDesignExplorer)
Loading required package: gsDesign
Loading required package: ggplot2
Loading required package: reshape
Loading required package: plyrAttaching package: 'reshape'
The following object(s) are masked from 'package:plyr':
rename, round_any
Loading required package: grid
Loading required package: proto
Loading required package: xtable
GsdState constructor called!
In DllMaingsDesignExplorer()
In GsdStartup
In GsdMain
In Init() function
Next line is call to new QApplication()...
Done with call to new QApplication()...
About to call the gsDesign constructor
In gsDesign constructor
Next line in code is call to ui->setupUi(this);...
In DllMain
QWidget: Must construct a QApplication before a QPaintDeviceThis application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
In DllMain
Destructor calledThis application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
@ -
[quote author="dnadave" date="1307582535"]Here is the compilation and an example run. I decorated the code with some printf's to show what is being called when. I do not understand the problem with QApplication as it was created many lines before the error shows up...
[/quote]We are at a point, where only a small example (fully compilable, showing the problem) could help analyzing.
-
Gerolf:
I'm working on creating a small example that both looks like my project and replicates the problem.
In the meantime, it looks like the problem centers around the fact that the application resides in a global instance and QApplication is not set up when the thread is attached. What I mean is when you look at the output below, you can see that we enter process attach, start the initialization process, create a new QApplication and then when we try to instantiate a new instance of the main application class, we enter thread attach and the application then thinks that QApplication has not been instantiated and dies.
Not sure why this works on Linux and Mac, but not on Windows.
@
library(gsDesignExplorer)
Loading required package: gsDesign
Loading required package: ggplot2
Loading required package: reshape
Loading required package: plyrAttaching package: 'reshape'
The following object(s) are masked from 'package:plyr':
rename, round_any
Loading required package: grid
Loading required package: proto
Loading required package: xtable
GsdState constructor called!
In DllMain, ul_reason_for_call = 1
In DLL_PROCESS_ATTACHgsDesignExplorer()
In GsdStartup
In GsdMain
In Init() function
Next line is call to new QApplication()...
Done with call to new QApplication()...
About to call the gsDesign constructor
In gsDesign constructor
Next line in code is call to ui->setupUi(this);...
In DllMain, ul_reason_for_call = 2
In DLL_THREAD_ATTACH
QWidget: Must construct a QApplication before a QPaintDeviceThis application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
In DllMain, ul_reason_for_call = 0
In DLL_PROCESS_DETACH
Destructor calledThis application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
@ -
Hi.
I'd like to up this post : doesn't seem to have any solution here and, as it happens, i have the exact same problem : the setupUi method crashed without apparent reason.
And this only happen on Windows and on Release mode (the bug isn't reproductible on Linux, or on Windows in debug mode).
I'm using Qt4.8.0, and I'm compiling with the MinGW provided with QtCreator.Here is some code from the header :
@#ifndef LEVELEDITOR_H
#define LEVELEDITOR_H#include <QWidget>
#include "texturemanager.h"
#include "objectmanager.h"namespace Ui {
class LevelEditor;
}class LevelEditor : public QWidget
{
Q_OBJECTpublic:
explicit LevelEditor(QWidget *parent = 0);
~LevelEditor();void Save(const QString& filepath); bool Load(const QString& name, const QString& filepath); void Test(const QString& workdir);
public slots:
void TextureAdded(QString);private slots:
void PickNewTexture(void);
void TextureListIndexChanged(int);
void TextureListUpdated(void);void CreateNewAnimation(void); void AddAnimationToList(QString); void ObjectListIndexChanged(int); void CreateNewObject(void); void ObjectListUpdated(void); void LandscapeChanged(QString); void UpdateLevelSize(void); void AddEntity(void); void DelEntity(void);
private:
Ui::LevelEditor *ui;
TextureManager _textureManager;
ObjectManager _objectManager;
AnimationManager _animationManager;
QString _currentLevel;
};#endif // LEVELEDITOR_H@
And here is the constructor :
@LevelEditor::LevelEditor(QWidget *parent) : QWidget(parent), ui(new Ui::LevelEditor)
{
qDebug() << "test1";
ui->setupUi(this);
qDebug() << "test2";
}@And here goes the application output :
@test1
The program has unexpectedly finished.
C:\Users\Lovestospooge\Documents\Editor-build-desktop-Qt_4_8_0__4_8_0__Release\release\Editor.exe exited with code -1073741819@If, during the past half year, you found something that may cause this, I'd be glad to know.
If not, then you're not the only one who met with this problem. And it may be interesting to get to the bottom of it :) !