Trying to declare QVector in a QDialog header file

  • I want to declare a QVector in a header file so that I can use it throughout the functions in the class.
    This seems so easy, and it works when I do it in a QMainWindow header, but it crashes ("Finishes unexpectedly") if I do the same thing in a QDialog header file. The code is below. If I uncomment the line: "//QVector<double> x,y;", the program compiles and crashes. I put the identical line in a QMainWindow header and it works exactly as I'd expect. The program runs, and the QVector is available to all of the functions in the MainWindow class. I assume I am missing something very basic.

    This is on a MAC, QT5.5.5, Creator 3.5.1, Opensource

    #ifndef GRAPH_H
    #define GRAPH_H

    #include <QDialog>
    #include <QDesktopWidget>

    namespace Ui {
    class graph;

    class graph : public QDialog

    explicit graph(QWidget *parent = 0);
    //QVector<double> x,y;
    void transfer_data(QVector<double> a, QVector<double> b);

    private slots:
    void on_makegraph1_clicked();

    Ui::graph *ui;

  • Qt Champions 2017

    Hi and welcome
    Does it crash if you just have in ?
    You dont do anything to it ?
    also did you try as
    QVector<double> x
    QVector<double> y;

  • Moderators

    Hi and welcome!
    When does it crash? When it is started? When you create an instance of graph? When you show the graph dialog?
    Why do you include QDesktopWidget?

  • It crashes just after I compile the program and before anything opens. The QDialog is called by a mainwindow, and the mainwindow doesn't even open.

    I put the QDesktopWidget in because I was hoping it would help; that call is in the MainWindow header, and the QVector declaration works there.

    I have tried declaring them separately (QVector<double> x; ...
    That crashes as well. ("The program has unexpectedly finished.").



  • Qt Champions 2017

    should also work in the dialog :)

    --The QDialog is called by a mainwindow
    can i see how u call it?

  • This is the calling statements. I tried instead, and got the same result.


  • Qt Champions 2017

    @pcheimets said:
    ok. and where do you declare it ?
    is it same function ?

    void Doti() {
    graph graphWindow;
    graph graphWindow; should be in a class or function. Not in global scope.

    what do transfer_data do ?
    can you show inside ?

    so in your sample, you send graphWindow 2 other lists ?
    transfer_data(x,y); << - those are other list you send to the graphWindow?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.