June 6, 2011

dnadave dnadave
Lab Rat
24 posts

Weird problem with setupUI call

 

I’m having some trouble getting a library to run using qwt, qt, and mingw on Windows 7. I can build and install the package without error. However, when I run the code, I can make it to

  1. ui->setupUI(this);

when it dies. I should point out that what I’m doing is creating a GUI for R (http:www.r-project.org) so the library is called from R and the error I’m getting is that R is shutdown with the message:

  1. This application has requested the Runtime to terminate it in an unusual way.
  2. Please contact the application's support team for more information.
  3. ERROR: loading failed

Anyone ever have trouble like this in their own applications before? I’m stumped as the call to ui->setupUI(this); seems so basic that there should not be any way for it to go wrong…

Thanks!!

Dave H

15 replies

June 6, 2011

Scylla Scylla
Lab Rat
238 posts

Please show more code i.e. complete constructor!

June 6, 2011

dnadave dnadave
Lab Rat
24 posts

OK. I was trying to save on the length of code…

Here is most of the constructor (I get an error that it is greater than 6000 characters trying to post the whole thing). The printf after the call to ui->setupUi(this); does not print. The code works on Linux…

  1. #if defined( __MINGW32__ )
  2. gsDesign::gsDesign( QWidget *parent ) : ui( new Ui::gsDesign )
  3. {
  4.  printf("Can we make it here...n");
  5.  ui->setupUi(this);
  6. #else
  7. gsDesign::gsDesign(QWidget *parent) :
  8.         QMainWindow(parent),
  9.         ui(new Ui::gsDesign)
  10. {
  11.  ui->setupUi(this);
  12. #endif
  13.  printf("Maybe here...n");
  14.  
  15.     // install event filters
  16.     ui->dnNameCombo->installEventFilter(this);
  17.  printf("Now, maybe here...n");
  18.     ui->dnDescCombo->installEventFilter(this);
  19.  
  20. ...
  21.  
  22.     ui->eptErrorHSlider->setScalePosition( QwtSlider::BottomScale );
  23.     ui->eptErrorHSlider->setRange( 0.0 , 100.0 , 0.1 );
  24.     ui->eptPowerHSlider->setScalePosition( QwtSlider::BottomScale );
  25.     ui->eptPowerHSlider->setRange( 0.0 , 100.0 , 0.5 );
  26.     ui->eptErrorHSlider->setValue( ui->eptErrorDSpin->value() );
  27.     ui->eptPowerHSlider->setValue( ui->eptPowerDSpin->value() );
  28. }

June 6, 2011

Gerolf Gerolf
Robot Herder
3286 posts

Why do you have the if defined / else / endif there ?
Did you try to debug it?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 6, 2011

dnadave dnadave
Lab Rat
24 posts

Mingw does not like the call to QMainWindow(parent), but it is apparently needed on the version of Qt I have installed on Linux. That’s the only reason.

I have tried running this through gdb, but have had some trouble as my version of R on windows was not built with the debug flags set. I should rebuild it with those flags set, but have not as of yet…

June 6, 2011

Scylla Scylla
Lab Rat
238 posts

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!

June 6, 2011

dnadave dnadave
Lab Rat
24 posts

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:

  1.  void Init(int argc, char *argv[])
  2.  {
  3.   if (m_pgsdApp == NULL)
  4.   {
  5.    m_pgsdApp = new QApplication(argc, argv);
  6.    QSplashScreen *m_pSplash = new QSplashScreen;
  7.    m_pSplash->setPixmap(QPixmap(":/images/splash/gsDesignSplash.png"));
  8.    m_pSplash->show();
  9.  
  10.    Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
  11.    m_pSplash->showMessage(QObject::tr("Loading graphical user interface ... "),
  12.            topRight, Qt::white);
  13.  
  14.    int delay = 3500;
  15.    QTimer::singleShot(delay, m_pSplash, SLOT(close()));
  16.  
  17.    m_pgsdApp->processEvents();
  18.  
  19.    m_gsdWindow = new gsDesign();
  20.  
  21.    QTimer::singleShot(delay, m_gsdWindow, SLOT(show()));
  22.   }
  23.  }

June 6, 2011

Scylla Scylla
Lab Rat
238 posts

If I use the constructor specified in the else clause of the #if defined statement, I do not even enter the constructor function.

This sounds weird. The constructor constructs always the object.
Maybe you should show us you header!

June 6, 2011

dnadave dnadave
Lab Rat
24 posts

Sure!

  1. namespace Ui {
  2.     class gsDesign;
  3. }
  4.  
  5. class gsDesign : public QMainWindow {
  6.     Q_OBJECT
  7. public:
  8.     gsDesign(QWidget *parent = 0);
  9.     ~gsDesign();
  10.     enum Spending { LowerSpending, UpperSpending };
  11.     enum MapAction { setMap, getMap };
  12.  
  13. protected:
  14.     void changeEvent(QEvent *e);
  15.     bool eventFilter(QObject *o, QEvent *e);
  16.  
  17. private slots:
  18.     void populatePlotFromDesignQMap();
  19.     void fillAnalysisTable(double *array, int len);
  20.     bool validatePiecewiseTables();
  21.     bool isValidPiecewiseTable(QTableWidget *table, QSpinBox *spin, int *emptyIndex);
  22.     double convertEventRate(double val);
  23.     void dnDescCombo_returnPressed();
  24.     void dnNameCombo_returnPressed();
  25.     void on_menuActionAutoscalePlot_toggled(bool );
  26.     void quit();
  27.     void on_menuActionExit_triggered();
  28.     void on_opYLabelLeftLine_editingFinished();
  29.     void on_opXLabelLine_editingFinished();
  30.     void on_opTitleLine_editingFinished();
  31.     void on_opPlotRenderCombo_currentIndexChanged(int index);
  32.     void on_menuActionPlotDefaults_triggered();
  33.     void informationHandler(QString information);
  34.     void warningHandler(QString warning);
  35.     void errorHandler(QString error);
  36.     bool exportAllDesigns();
  37.     void on_menuActionExportAllDesigns_triggered();
  38.     void on_toolbarActionSetWorkingDirectory_triggered();
  39.     bool setWorkingDirectory();
  40.     void on_menuActionChangeWorkingDirectory_triggered();
  41.     void on_toolbarActionEditPlot_triggered();
  42.     void on_menuActionExportPlot_triggered();
  43.     void exportPlot();
  44.     void on_toolbarActionExportPlot_triggered();
  45.     QMap<QString, QString> updateDesignMap();
  46.     QString QComboBoxIndexToQString(QComboBox *combo);
  47.     QString QDoubleSpinBoxValueToQString(QwtCounter *dspin);
  48.     QString QSpinBoxValueToQString(QSpinBox *spin);
  49.     QString QTableWidgetToQString(QTableWidget *table);
  50.     QString strippedName(const QString &fullFileName);
  51.     bool exportDesign();
  52.     bool save();
  53.     bool saveAs();
  54.     bool saveFile(const QString &fileName);
  55.     bool writeFile(const QString &fileName);
  56.     void about();
  57.     void addNewDesign();
  58.     void contextHelp();
  59.     void deleteDesign();
  60.     void designMapToQComboBox(QComboBox *combo);
  61. ...
  62.     // QList of QMaps comprising design list
  63.     QList<QMap<QString, QString> > designList;
  64.     QMap<QString, QString> defaultDesign;
  65.  
  66.     // File I/O
  67.     QString currentDesignFile;
  68.     QString plotFilePath;
  69.     QDir currentWorkingDirectory;
  70. };

June 7, 2011

Gerolf Gerolf
Robot Herder
3286 posts

The constructor MUST look like this:

  1. gsDesign::gsDesign(QWidget *parent) :
  2.         QMainWindow(parent),
  3.         ui(new Ui::gsDesign)
  4. {
  5.  printf("Can we make it here...n");
  6.  ui->setupUi(this);
  7.  printf("Maybe here...n");

perhaps you should rename the UI class in the ui file:

  1. namespace Ui {
  2.     class gsDesignUI;
  3. }

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 8, 2011

dnadave dnadave
Lab Rat
24 posts

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

June 9, 2011

dnadave dnadave
Lab Rat
24 posts

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:

  1. dnadave@ecthgow-vm /c/Users/dnadave/workspace/GSDesignGUI/trunk/package
  2. $ R CMD INSTALL --no-clean-on-error gsDesignExplorer
  3. * installing to library 'c:/Program Files/R/R-2.13.0/library'
  4. * installing *source* package 'gsDesignExplorer' ...
  5. ** libs
  6.   running src/Makefile.win ...
  7. mkdir -p ../explorergui-build;
  8.         cd ../explorergui-build;
  9.         CC="c:/rtools/mingw/bin/gcc.exe" CXX="c:/rtools/mingw/bin/g++.exe"
  10.         cmake -G "MSYS Makefiles" ../src -DR_LIBRARIES="-Lc:/PROGRA~1/R/R-213~1.
  11. 0/bin/i386 -lR -L../inst/libs/i386"
  12.         -DR_INCLUDES=c:/PROGRA~1/R/R-213~1.0/include -DCMAKE_INSTALL_PREFIX=../i
  13. nst/libs/i386/;
  14.         make install;
  15.         cp ../inst/libs/i386/bin/*.dll ../inst/libs/i386;
  16.         rm -rf ../inst/libs/i386/bin;
  17.         cp -Ru ../src/images/ ../inst
  18. -- The C compiler identification is GNU
  19. -- The CXX compiler identification is GNU
  20. -- Check for working C compiler: c:/Rtools/MinGW/bin/gcc.exe
  21. -- Check for working C compiler: c:/Rtools/MinGW/bin/gcc.exe -- works
  22. -- Detecting C compiler ABI info
  23. -- Detecting C compiler ABI info - done
  24. -- Check for working CXX compiler: c:/Rtools/MinGW/bin/g++.exe
  25. -- Check for working CXX compiler: c:/Rtools/MinGW/bin/g++.exe -- works
  26. -- Detecting CXX compiler ABI info
  27. -- Detecting CXX compiler ABI info - done
  28. -- Looking for Q_WS_X11
  29. -- Looking for Q_WS_X11 - not found.
  30. -- Looking for Q_WS_WIN
  31. -- Looking for Q_WS_WIN - found
  32. -- Looking for Q_WS_QWS
  33. -- Looking for Q_WS_QWS - not found.
  34. -- Looking for Q_WS_MAC
  35. -- Looking for Q_WS_MAC - not found.
  36. -- Found Qt-Version 4.7.3 (using c:/QtSDK/Desktop/Qt/4.7.3/mingw/bin/qmake.exe)
  37. -- Found Qwt: C:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExplo
  38. rer/inst/libs/i386/qwtd5.dll
  39. -- Configuring done
  40. -- Generating done
  41. -- Build files have been written to: C:/Users/dnadave/workspace/GSDesignGUI/trun
  42. k/package/gsDesignExplorer/explorergui-build
  43. [  8%] Generating ui_gsdesign.h
  44. [ 16%] Building CXX object CMakeFiles/gsDesignExplorer.dir/Rcpp.cpp.obj
  45. [ 25%] Building CXX object CMakeFiles/gsDesignExplorer.dir/gsdesign.cpp.obj
  46. [ 33%] Building CXX object CMakeFiles/gsDesignExplorer.dir/gsDesignGUI.cpp.obj
  47. [ 41%] Building CXX object CMakeFiles/gsDesignExplorer.dir/gsDesignTips.cpp.obj
  48. [ 50%] Building CXX object CMakeFiles/gsDesignExplorer.dir/GsRList.cpp.obj
  49. [ 58%] Building CXX object CMakeFiles/gsDesignExplorer.dir/main.cpp.obj
  50. c:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExplorer/src/main.c
  51. pp:165:37: warning: unused parameter 'hModule'
  52. c:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExplorer/src/main.c
  53. pp:165:37: warning: unused parameter 'lpReserved'
  54. [ 66%] Generating gsDesignExplorer.def
  55. [ 75%] Generating moc_gsdesign.cxx
  56. [ 83%] Generating qrc_images.cxx
  57. Scanning dependencies of target gsDesignExplorer
  58. [ 91%] Building CXX object CMakeFiles/gsDesignExplorer.dir/moc_gsdesign.cxx.obj
  59. [100%] Building CXX object CMakeFiles/gsDesignExplorer.dir/qrc_images.cxx.obj
  60. Linking CXX shared library libgsDesignExplorer.dll
  61. Creating library file: libgsDesignExplorer.dll.a
  62. [100%] Built target gsDesignExplorer
  63. Install the project...
  64. -- Install configuration: ""
  65. -- Installing: C:/Users/dnadave/workspace/GSDesignGUI/trunk/package/gsDesignExpl
  66. orer/inst/libs/i386/./libgsDesignExplorer.dll

Example run:

  1. dnadave@ecthgow-vm ~
  2. $ R
  3.  
  4. R version 2.13.0 (2011-04-13)
  5. Copyright (C) 2011 The R Foundation for Statistical Computing
  6. ISBN 3-900051-07-0
  7. Platform: i386-pc-mingw32/i386 (32-bit)
  8.  
  9. R is free software and comes with ABSOLUTELY NO WARRANTY.
  10. You are welcome to redistribute it under certain conditions.
  11. Type 'license()' or 'licence()' for distribution details.
  12.  
  13.   Natural language support but running in an English locale
  14.  
  15. R is a collaborative project with many contributors.
  16. Type 'contributors()' for more information and
  17. 'citation()' on how to cite R or R packages in publications.
  18.  
  19. Type 'demo()' for some demos, 'help()' for on-line help, or
  20. 'help.start()' for an HTML browser interface to help.
  21. Type 'q()' to quit R.
  22.  
  23. > library(gsDesignExplorer)
  24. Loading required package: gsDesign
  25. Loading required package: ggplot2
  26. Loading required package: reshape
  27. Loading required package: plyr
  28.  
  29. Attaching package: 'reshape'
  30.  
  31. The following object(s) are masked from 'package:plyr':
  32.  
  33.     rename, round_any
  34.  
  35. Loading required package: grid
  36. Loading required package: proto
  37. Loading required package: xtable
  38. GsdState constructor called!
  39. In DllMain
  40. > gsDesignExplorer()
  41. In GsdStartup
  42. In GsdMain
  43. In Init() function
  44. Next line is call to new QApplication()...
  45. Done with call to new QApplication()...
  46. About to call the gsDesign constructor
  47. In gsDesign constructor
  48. Next line in code is call to ui->setupUi(this);...
  49. In DllMain
  50. QWidget: Must construct a QApplication before a QPaintDevice
  51.  
  52. This application has requested the Runtime to terminate it in an unusual way.
  53. Please contact the application's support team for more information.
  54. In DllMain
  55. Destructor called
  56.  
  57. This application has requested the Runtime to terminate it in an unusual way.
  58. Please contact the application's support team for more information.

June 9, 2011

Scylla Scylla
Lab Rat
238 posts

You can see in you output that the constructor of you “GsdState” is called before “Next line is call to new QApplication().”. This is wrong. You have to create the QApplication object before “GsdState”.

June 9, 2011

Gerolf Gerolf
Robot Herder
3286 posts
dnadave wrote:
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…

We are at a point, where only a small example (fully compilable, showing the problem) could help analyzing.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

June 10, 2011

dnadave dnadave
Lab Rat
24 posts

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.

  1. > library(gsDesignExplorer)
  2. Loading required package: gsDesign
  3. Loading required package: ggplot2
  4. Loading required package: reshape
  5. Loading required package: plyr
  6.  
  7. Attaching package: 'reshape'
  8.  
  9. The following object(s) are masked from 'package:plyr':
  10.  
  11.     rename, round_any
  12.  
  13. Loading required package: grid
  14. Loading required package: proto
  15. Loading required package: xtable
  16. GsdState constructor called!
  17. In DllMain, ul_reason_for_call = 1
  18. In DLL_PROCESS_ATTACH
  19. > gsDesignExplorer()
  20. In GsdStartup
  21. In GsdMain
  22. In Init() function
  23. Next line is call to new QApplication()...
  24. Done with call to new QApplication()...
  25. About to call the gsDesign constructor
  26. In gsDesign constructor
  27. Next line in code is call to ui->setupUi(this);...
  28. In DllMain, ul_reason_for_call = 2
  29. In DLL_THREAD_ATTACH
  30. QWidget: Must construct a QApplication before a QPaintDevice
  31.  
  32. This application has requested the Runtime to terminate it in an unusual way.
  33. Please contact the application's support team for more information.
  34. In DllMain, ul_reason_for_call = 0
  35. In DLL_PROCESS_DETACH
  36. Destructor called
  37.  
  38. This application has requested the Runtime to terminate it in an unusual way.
  39. Please contact the application's support team for more information.

February 19, 2012

plaristote plaristote
Lab Rat
2 posts

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 :

  1. #ifndef LEVELEDITOR_H
  2. #define LEVELEDITOR_H
  3.  
  4. #include <QWidget>
  5. #include "texturemanager.h"
  6. #include "objectmanager.h"
  7.  
  8. namespace Ui {
  9. class LevelEditor;
  10. }
  11.  
  12. class LevelEditor : public QWidget
  13. {
  14.     Q_OBJECT
  15.    
  16. public:
  17.     explicit LevelEditor(QWidget *parent = 0);
  18.     ~LevelEditor();
  19.  
  20.     void Save(const QString& filepath);
  21.     bool Load(const QString& name, const QString& filepath);
  22.     void Test(const QString& workdir);
  23.  
  24. public slots:
  25.     void TextureAdded(QString);
  26.  
  27. private slots:
  28.     void PickNewTexture(void);
  29.     void TextureListIndexChanged(int);
  30.     void TextureListUpdated(void);
  31.  
  32.     void CreateNewAnimation(void);
  33.     void AddAnimationToList(QString);
  34.  
  35.     void ObjectListIndexChanged(int);
  36.     void CreateNewObject(void);
  37.     void ObjectListUpdated(void);
  38.  
  39.     void LandscapeChanged(QString);
  40.     void UpdateLevelSize(void);
  41.     void AddEntity(void);
  42.     void DelEntity(void);
  43.  
  44. private:
  45.     Ui::LevelEditor  *ui;
  46.     TextureManager   _textureManager;
  47.     ObjectManager    _objectManager;
  48.     AnimationManager _animationManager;
  49.     QString          _currentLevel;
  50. };
  51.  
  52. #endif // LEVELEDITOR_H

And here is the constructor :

  1. LevelEditor::LevelEditor(QWidget *parent) : QWidget(parent), ui(new Ui::LevelEditor)
  2. {
  3.     qDebug() << "test1";
  4.     ui->setupUi(this);
  5.     qDebug() << "test2";
  6. }

And here goes the application output :

  1. test1
  2. The program has unexpectedly finished.
  3. 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 :) !

 
  ‹‹ [Solved] Custom Widget with layout doesn’t resize      QWT Zoomer Problems ››

You must log in to post a reply. Not a member yet? Register here!