Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Weird problem with setupUI call
QtWS25 Last Chance

Weird problem with setupUI call

Scheduled Pinned Locked Moved 3rd Party Software
16 Posts 5 Posters 13.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dnadave
    wrote on 6 Jun 2011, 18:25 last edited by
    #1

    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

    @
    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:

    @
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Scylla
      wrote on 6 Jun 2011, 18:31 last edited by
      #2

      Please show more code i.e. complete constructor!

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dnadave
        wrote on 6 Jun 2011, 19:57 last edited by
        #3

        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...

        @
        #if defined( MINGW32 )
        gsDesign::gsDesign( QWidget *parent ) : ui( new Ui::gsDesign )
        {
        printf("Can we make it here...n");
        ui->setupUi(this);
        #else
        gsDesign::gsDesign(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::gsDesign)
        {
        ui->setupUi(this);
        #endif
        printf("Maybe here...n");

        // install event filters
        ui->dnNameCombo->installEventFilter(this);
        

        printf("Now, maybe here...n");
        ui->dnDescCombo->installEventFilter(this);

        ...

        ui->eptErrorHSlider->setScalePosition( QwtSlider::BottomScale );
        ui->eptErrorHSlider->setRange( 0.0 , 100.0 , 0.1 );
        ui->eptPowerHSlider->setScalePosition( QwtSlider::BottomScale );
        ui->eptPowerHSlider->setRange( 0.0 , 100.0 , 0.5 );
        ui->eptErrorHSlider->setValue( ui->eptErrorDSpin->value() );
        ui->eptPowerHSlider->setValue( ui->eptPowerDSpin->value() );
        

        }
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on 6 Jun 2011, 20:00 last edited by
          #4

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

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dnadave
            wrote on 6 Jun 2011, 20:03 last edited by
            #5

            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...

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Scylla
              wrote on 6 Jun 2011, 20:28 last edited by
              #6

              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!

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dnadave
                wrote on 6 Jun 2011, 20:39 last edited by
                #7

                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()));
                }
                }
                @

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Scylla
                  wrote on 6 Jun 2011, 20:46 last edited by
                  #8

                  bq. 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!

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dnadave
                    wrote on 6 Jun 2011, 20:52 last edited by
                    #9

                    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;
                    

                    };
                    @

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on 7 Jun 2011, 05:43 last edited by
                      #10

                      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;
                      }
                      @

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

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dnadave
                        wrote on 8 Jun 2011, 21:36 last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dnadave
                          wrote on 9 Jun 2011, 01:22 last edited by
                          #12

                          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 ~
                          $ R

                          R 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: plyr

                          Attaching 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

                          gsDesignExplorer()
                          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 QPaintDevice

                          This 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 called

                          This application has requested the Runtime to terminate it in an unusual way.
                          Please contact the application's support team for more information.
                          @

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            Scylla
                            wrote on 9 Jun 2011, 05:48 last edited by
                            #13

                            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".

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on 9 Jun 2011, 07:40 last edited by
                              #14

                              [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.

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

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                dnadave
                                wrote on 10 Jun 2011, 19:13 last edited by
                                #15

                                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: plyr

                                Attaching 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_ATTACH

                                gsDesignExplorer()
                                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 QPaintDevice

                                This 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 called

                                This application has requested the Runtime to terminate it in an unusual way.
                                Please contact the application's support team for more information.
                                @

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  plaristote
                                  wrote on 19 Feb 2012, 03:32 last edited by
                                  #16

                                  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_OBJECT

                                  public:
                                  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 :) !

                                  1 Reply Last reply
                                  1

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved