Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileSystemModel/TreeView - issues
Qt 6.12 LTS 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 6.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

    @J-Hilk
    Might be here in header?

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H

    J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #8

    @jacob-n nope, like the compiler I only see the function declaration


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    1
    • J jacob.n

      @J-Hilk
      Might be here in header?

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QMainWindow>

      QT_BEGIN_NAMESPACE
      namespace Ui { class MainWindow; }
      QT_END_NAMESPACE

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      MainWindow(QWidget *parent = nullptr);
      ~MainWindow();

      private:
      Ui::MainWindow *ui;
      };
      #endif // MAINWINDOW_H

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

      @jacob-n
      Exactly as @J-Hilk says. If you have the method declaration ~MainWindow(); in the class header you must supply the method definition/implementation somewhere, e.g. in the .cpp.

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

        As I posted mainwindow.h and mainwindow.cpp, there is only last available option - main.cpp
        Seems ok for me, but still in QT for 130 hours, still lacking a lot of basic syntax..

        Please give me the lead, folks :D

        #include "mainwindow.h"

        #include <QApplication>

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
        }

        JonBJ 1 Reply Last reply
        0
        • J jacob.n

          As I posted mainwindow.h and mainwindow.cpp, there is only last available option - main.cpp
          Seems ok for me, but still in QT for 130 hours, still lacking a lot of basic syntax..

          Please give me the lead, folks :D

          #include "mainwindow.h"

          #include <QApplication>

          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
          return a.exec();
          }

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

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

          Seems ok for me, but still in QT for 130 hours, still lacking a lot of basic syntax..

          You said earlier "I'm experienced in C/C++, php.". This issue has nothing to do with Qt, or its syntax (which it does not have as it is not a language). It is just standard, basic C++.

          As I posted mainwindow.h and mainwindow.cpp, there is only last available option - main.cpp

          No this has nothing to do with main.cpp.

          In your first post you showed the body of mainwindow.cpp. Where does that provide the definition for MainWindow::~MainWindow()?

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

            Here, constructor and desctructor

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

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

            JonBJ 1 Reply Last reply
            0
            • 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 Online
                            Christian EhrlicherC Online
                            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
                                • Unsolved