Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] std::vector declaration causes Qt application to crash
QtWS25 Last Chance

[Solved] std::vector declaration causes Qt application to crash

Scheduled Pinned Locked Moved General and Desktop
vectorstdcrashruntime
6 Posts 5 Posters 4.5k 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.
  • AslundA Offline
    AslundA Offline
    Aslund
    wrote on last edited by Aslund
    #1

    Hey Qt Forum

    My name is Sebastian Aslund and I have previously been using Qt during my studies.
    I have returned to Qt again due to my work as development engineer where I promoted Qt as our future GUI for our software,

    Currently I am developing a small sample to show Qt with OpenGL.
    My problem is that when I have std::vector<double> xData and std::vector<double> yData declared the program will compile but crash before showing the GUI.
    It simply returns The program has unexpectedly finished. If I comment these two vectors it compile and run without problems.
    I am very puzzled by this behavior and I hope someone can help figuring out how to solve it without resolving to use QVector.

    #ifndef MYGLWIDGET_H
    #define MYGLWIDGET_H
    
    #include <QGLWidget>
    #include <iostream>
    #include <vector>
    
    class MyGLWidget : public QGLWidget
    {
        Q_OBJECT
    public:
        explicit MyGLWidget(QWidget *parent = 0);
    
    protected:
        void initializeGL();
        void paintGL();
        void resizeGL(int width, int height);
    
    private:
        std::vector<double> xData;
        std::vector<double> yData;
        bool graphify;
        QRegExp delim;
    
    signals:
    
    public slots:
        void doGraphify(bool button);
        void getXData(QString xDataString);
        void getYData(QString yDataString);
    
    };
    
    #endif // MYGLWIDGET_H*
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      the first thing I can suggest is to Debug the code and try to understand where is the crash.

      If I comment these two vectors it compile and run without problems.

      This means the vectors are not used in your code, right?

      You should also check if there's in some part of your code some #define with vector

      Have you tried to use QVector instead of std::vector?

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      1
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        I have added code tags to your post.
        As @mcosta is sugesting basically. From personal experience I can tell you that it is not a problem of std::vector. I am using it all the time together with Qt.
        Even though I am not using QVector I would suggest as an alternative at least for finding the real problem.
        The definition of std::vector in your case is pushing the code and memory around. When the program is crashing only because you have defined the vector, it looks like a pointer issue IMHO.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        1
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          Problems raising after simple code modifications usually are sign of the stack corruption which happened earlier.

          1 Reply Last reply
          1
          • AslundA Offline
            AslundA Offline
            Aslund
            wrote on last edited by
            #5

            Hello guys

            Thanks a lot for the answers.
            Your replies got me thinking and I recalled how includes can mess things up.
            I removed a couple of the include files in some of my header files that turned out to be unnecessary.
            After removing all the header files while still being able to compile then the program was running again perfectly.

            Regards
            Sebastian Aslund

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BTT1
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0

              • Login

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