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. QFileSystemModel/TreeView - issues
Qt 6.11 is out! See what's new in the release blog

QFileSystemModel/TreeView - issues

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 6 Posters 5.2k 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.
  • J jacob.n

    Here, constructor and desctructor

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #13

    @jacob-n
    OK, but that MainWindow::~MainWindow() was not in what you posted earlier, was it? Given that, if you recompile now you should not get the undefined reference to MainWindow::~MainWindow() error that you showed earlier?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jacob.n
      wrote on last edited by jacob.n
      #14

      Yeah, fixed that one. Thank you!
      Can you please help with next issue, I found how to save data to kind of table and output.
      Please advise alternative way to output data from array without saving into temporary table.
      #include "Dialog.h"
      #include "ui_Dialog.h"

      Dialog::Dialog(QWidget *parent)
      : QDialog(parent)
      , ui(new Ui::Dialog)
      {
      ui->setupUi(this);

      model = new QStandardItemModel(5,2, this);
      
      ui->tableView->setModel(model);
      QModelIndex index;
      
      for (int row = 0; row < model->rowCount(); ++row)
      {
         for (int col = 0; col < model ->columnCount(); ++col)
         {
            index = model->index (row,col);
            model->setData(index,9);
         }
      
      }
      

      }

      Dialog::~Dialog()
      {
      delete ui;
      }

      Thanks in advance,
      Jacob N

      JonBJ 1 Reply Last reply
      0
      • J jacob.n

        Yeah, fixed that one. Thank you!
        Can you please help with next issue, I found how to save data to kind of table and output.
        Please advise alternative way to output data from array without saving into temporary table.
        #include "Dialog.h"
        #include "ui_Dialog.h"

        Dialog::Dialog(QWidget *parent)
        : QDialog(parent)
        , ui(new Ui::Dialog)
        {
        ui->setupUi(this);

        model = new QStandardItemModel(5,2, this);
        
        ui->tableView->setModel(model);
        QModelIndex index;
        
        for (int row = 0; row < model->rowCount(); ++row)
        {
           for (int col = 0; col < model ->columnCount(); ++col)
           {
              index = model->index (row,col);
              model->setData(index,9);
           }
        
        }
        

        }

        Dialog::~Dialog()
        {
        delete ui;
        }

        Thanks in advance,
        Jacob N

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #15

        @jacob-n
        Your code just shows putting some data into the model. I don't know what you mean by "output data" and where a "temporary table" is involved.

        If you mean you don't need/want the data storage provided by a QStandardItemModel, e.g. you have your own data in an array, look at QAbstractTableModel Class and the Subclassing section instead. All you have to do is

        When subclassing QAbstractTableModel, you must implement rowCount(), columnCount(), and data().

        Just tie those to your array.

        Editable models need to implement setData(), and implement flags() to return a value containing Qt::ItemIsEditable.

        And implement setData() to write into your array.

        Once you have that you can replace the QStandardItemModel with it and the QTableView will work the same but use your array as the model.

        1 Reply Last reply
        1
        • J Offline
          J Offline
          jacob.n
          wrote on last edited by jacob.n
          #16

          Hello there!

          qDebug() << ui->tableView->model()->index(0,0).data();
          outputting to console this:
          QVariant(int, 1)
          I just need to return to function this int value.

          like
          return ui->tableView->model()->index(0,0).data();
          return tableView.getData(something);

          What is the proper syntax ?

          BR

          Jacob

          jsulmJ 1 Reply Last reply
          0
          • J jacob.n

            Hello there!

            qDebug() << ui->tableView->model()->index(0,0).data();
            outputting to console this:
            QVariant(int, 1)
            I just need to return to function this int value.

            like
            return ui->tableView->model()->index(0,0).data();
            return tableView.getData(something);

            What is the proper syntax ?

            BR

            Jacob

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #17

            @jacob-n said in QFileSystemModel/TreeView - issues:

            I just need to return to function this int value

            https://doc.qt.io/qt-5/qvariant.html#toInt

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

            1 Reply Last reply
            1
            • I Offline
              I Offline
              icebergenergy
              wrote on last edited by
              #18
              This post is deleted!
              1 Reply Last reply
              0
              • J Offline
                J Offline
                jacob.n
                wrote on last edited by
                #19

                is there a way to convert from QVariant to std string?

                Christian EhrlicherC 1 Reply Last reply
                0
                • J jacob.n

                  is there a way to convert from QVariant to std string?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #20

                  @jacob-n said in QFileSystemModel/TreeView - issues:

                  is there a way to convert from QVariant to std string?

                  Convert it to a QString and then to a std::string.

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

                  1 Reply Last reply
                  1
                  • J Offline
                    J Offline
                    jacob.n
                    wrote on last edited by
                    #21

                    done! Thank you!
                    How do you guys make back up with QT?
                    If I just copy folder and trying to open project from new folder it will not build good.
                    Please advise

                    jsulmJ 1 Reply Last reply
                    0
                    • J jacob.n

                      done! Thank you!
                      How do you guys make back up with QT?
                      If I just copy folder and trying to open project from new folder it will not build good.
                      Please advise

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #22

                      @jacob-n said in QFileSystemModel/TreeView - issues:

                      How do you guys make back up with QT?

                      Using a proper code version system like Git.

                      "If I just copy folder and trying to open project from new folder it will not build good." - what exactly happens? You probably need to delete the *.pro.user file.

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

                      1 Reply Last reply
                      1

                      • Login

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