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. Trying to declare QVector in a QDialog header file
Forum Updated to NodeBB v4.3 + New Features

Trying to declare QVector in a QDialog header file

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 2.1k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pcheimets
    wrote on last edited by
    #1

    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
    {
    Q_OBJECT

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

    private slots:
    void on_makegraph1_clicked();

    private:
    Ui::graph *ui;

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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;

      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pcheimets
          wrote on last edited by
          #4

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

          Thanks

          Peter

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            should also work in the dialog :)

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

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pcheimets
              wrote on last edited by
              #6

              This is the calling statements. I tried ...show() instead, and got the same result.

              graphWindow.transfer_data(x,y);
              
              graphWindow.exec();
              
              mrjjM 1 Reply Last reply
              0
              • P pcheimets

                This is the calling statements. I tried ...show() instead, and got the same result.

                graphWindow.transfer_data(x,y);
                
                graphWindow.exec();
                
                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

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

                void Doti() {
                graph graphWindow;
                graphWindow.transfer_data(x,y);
                graphWindow.exec();
                }
                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?

                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