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. problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing
QtWS25 Last Chance

problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing

Scheduled Pinned Locked Moved Solved General and Desktop
qt c++qsqltablemodeluniqueptrqtableview
5 Posts 2 Posters 449 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on 3 Jan 2024, 11:51 last edited by
    #1

    Hi ~~ I Have A problem Using unique_ptr

    std::unique_ptr<QSqlTableModel> freshModel(new QSqlTableModel(ui->clientstableview_2));
        freshModel->setTable("clients");
        freshModel->select();
    
        if (!freshModel->select()) {
            qDebug() << "Error in select:" << freshModel->lastError().text();
        } else {
            qDebug() << "working ~ row count="<<freshModel->rowCount();
        }
        ui->clientstableview_2->setModel(freshModel.get());
        qDebug()<<"HeaderData 0 ="<<ui->clientstableview_2->model()->headerData(0,Qt::Horizontal).toString();
         // tableView has the data correctly but the TableView Show Nothing ... ~!
    

    is there any solution for that?

    C 1 Reply Last reply 3 Jan 2024, 11:55
    0
    • P Proton Phoenix
      3 Jan 2024, 12:05

      @Christian-Ehrlicher said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

      @Proton-Phoenix said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

      is there any solution for that

      Don't use a shared pointer or make sure it is alive as long as the tableview.

      Yep i am sure it's alive , debugging data in the QTableView , and it's there without any problem, but it doesn't show those data only empty tableView !@Christian-Ehrlicher

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 3 Jan 2024, 12:20 last edited by
      #4

      No, the model is not alive after the unique pointer destroys it...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      P 1 Reply Last reply 3 Jan 2024, 12:32
      2
      • P Proton Phoenix
        3 Jan 2024, 11:51

        Hi ~~ I Have A problem Using unique_ptr

        std::unique_ptr<QSqlTableModel> freshModel(new QSqlTableModel(ui->clientstableview_2));
            freshModel->setTable("clients");
            freshModel->select();
        
            if (!freshModel->select()) {
                qDebug() << "Error in select:" << freshModel->lastError().text();
            } else {
                qDebug() << "working ~ row count="<<freshModel->rowCount();
            }
            ui->clientstableview_2->setModel(freshModel.get());
            qDebug()<<"HeaderData 0 ="<<ui->clientstableview_2->model()->headerData(0,Qt::Horizontal).toString();
             // tableView has the data correctly but the TableView Show Nothing ... ~!
        

        is there any solution for that?

        C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 3 Jan 2024, 11:55 last edited by
        #2

        @Proton-Phoenix said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

        is there any solution for that

        Don't use a shared pointer or make sure it is alive as long as the tableview.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        P 1 Reply Last reply 3 Jan 2024, 12:05
        2
        • C Christian Ehrlicher
          3 Jan 2024, 11:55

          @Proton-Phoenix said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

          is there any solution for that

          Don't use a shared pointer or make sure it is alive as long as the tableview.

          P Offline
          P Offline
          Proton Phoenix
          wrote on 3 Jan 2024, 12:05 last edited by
          #3

          @Christian-Ehrlicher said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

          @Proton-Phoenix said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

          is there any solution for that

          Don't use a shared pointer or make sure it is alive as long as the tableview.

          Yep i am sure it's alive , debugging data in the QTableView , and it's there without any problem, but it doesn't show those data only empty tableView !@Christian-Ehrlicher

          C 1 Reply Last reply 3 Jan 2024, 12:20
          0
          • P Proton Phoenix
            3 Jan 2024, 12:05

            @Christian-Ehrlicher said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

            @Proton-Phoenix said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

            is there any solution for that

            Don't use a shared pointer or make sure it is alive as long as the tableview.

            Yep i am sure it's alive , debugging data in the QTableView , and it's there without any problem, but it doesn't show those data only empty tableView !@Christian-Ehrlicher

            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 3 Jan 2024, 12:20 last edited by
            #4

            No, the model is not alive after the unique pointer destroys it...

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            P 1 Reply Last reply 3 Jan 2024, 12:32
            2
            • C Christian Ehrlicher
              3 Jan 2024, 12:20

              No, the model is not alive after the unique pointer destroys it...

              P Offline
              P Offline
              Proton Phoenix
              wrote on 3 Jan 2024, 12:32 last edited by
              #5

              @Christian-Ehrlicher said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

              ah I understand now , many Thanks bro <3 i will try another solution
              really I Appreciate Your PROFESSIONAL Support <3

              1 Reply Last reply
              0
              • P Proton Phoenix has marked this topic as solved on 3 Jan 2024, 12:32

              5/5

              3 Jan 2024, 12:32

              • Login

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