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. App crashes on model->rowCount()
Forum Updated to NodeBB v4.3 + New Features

App crashes on model->rowCount()

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.1k Views 2 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
    Panoss
    wrote on last edited by Panoss
    #1

    The model is a QSqlTableModel. (declared this way: QSqlTableModel *manufacturers_tbl_model;)
    In the clicked slot of a pushbutton, I have this code.

    void RepairDevices::on_manufacturers_add_btn_clicked()
    {
        int row = manufacturers_tbl_model->rowCount();
    }
    

    And when I click the button, the application just...crashes!!!
    What am I doing wrong?

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      It's hard to tell without more information such as a stack trace or complete example. By any chance is manufacturers_tbl_model uninitialized?

      Asking a question about code? http://eel.is/iso-c++/testcase/

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

        Hi,

        Is manufacturers_tbl_model pointing to something valid ? i.e. did you do manufacturers_tbl_model = new QSqlTableModel; in the constructor or RepairDevices ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

          Hi guys.
          Yes it is initialised:

          QSqlTableModel *manufacturers_tbl_model = new QSqlTableModel;
          manufacturers_tbl_model->setTable("manufacturers");
          ui.manufacturers_tbl->setModel(manufacturers_tbl_model);
          manufacturers_tbl_model->select();
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            No it's not, you're shadowing your member variable.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            4
            • P Offline
              P Offline
              Panoss
              wrote on last edited by
              #6

              What do you mean SGaist?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Panoss
                wrote on last edited by
                #7

                I replaced:

                QSqlTableModel *manufacturers_tbl_model = new QSqlTableModel;
                

                with:

                 manufacturers_tbl_model = new QSqlTableModel;
                

                and does not crash anymore!!
                Is this what you meant SGaist?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Yes, that's what I meant.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2

                  • Login

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