[Solved] std::vector declaration causes Qt application to crash
-
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*
-
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
withvector
Have you tried to use
QVector
instead ofstd::vector
? -
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. -
Problems raising after simple code modifications usually are sign of the stack corruption which happened earlier.
-
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