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. invalid use of incomplete type 'class QFileSystemModel' when using a class for a model
Forum Updated to NodeBB v4.3 + New Features

invalid use of incomplete type 'class QFileSystemModel' when using a class for a model

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.8k 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.
  • N Offline
    N Offline
    NoticeMeSenpai
    wrote on 12 Jul 2018, 02:18 last edited by
    #1

    Hey all, brand new to both QT as well as C++ and was looking for some assistance with an issue I'm having. Sorry in advance if this is the wrong section of the forum, please let me know where I should direct my post to in that case.

    I'm having an issue with using the QFileSystemModel with the QTreeView widget I have set up in UI. The exact error I get is "invalid use of incomplete type 'class QFileSystemModel'
    ui->tvListBox->setModel((m_model->getModel()));
    ^
    "

    When I compile, I get the following error and am feeling really lost as I don't understand why it won't recognize the QFileSystemModel I set up. It works fine when I use the QFileSystemModel from within the "configTab" class directly but, I'm guessing I goofed at some point when I pushed the actual model into another class named "configModel".

    Here's the full project, in case my code isn't clear https://www.dropbox.com/s/4cm144nkuf1vw4w/Editor.zip?dl=0

    Sorry in advance for the code dump.

    Model/configmodel.h

    #ifndef CONFIGMODEL_H
    #define CONFIGMODEL_H
    #include <QWidget>
    
    class QFileSystemModel;
    class QAbstractItemModel;
    class QDir;
    
    class configModel
    {
    public:
        configModel();
        QFileSystemModel getModel();
    
    private:
        QFileSystemModel *m_fileModel;
    };
    #endif // CONFIGMODEL_H
    

    Model/configmodel.cpp

    #include "configmodel.h"
    #include "QFileSystemModel"
    #include "QDir"
    
    configModel::configModel() :
        m_fileModel(new QFileSystemModel) //create the file model
    {
        //set test model
        m_fileModel->setRootPath(QDir::currentPath());
    }
    
    QFileSystemModel configModel::getModel()
    {
        return m_fileModel;
    }
    

    View/configtab.h

    #ifndef CONFIGTAB_H
    #define CONFIGTAB_H
    
    #include <QWidget>
    
    namespace Ui {
        class ConfigTab;
    }
    
    class configModel;
    
    class ConfigTab : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit ConfigTab(QWidget *parent = 0);
        ~ConfigTab();
    
    private:
        Ui::ConfigTab *ui;
        configModel *m_model;
    };
    
    #endif // CONFIGTAB_H
    

    View/configtab.cpp

    #include "configtab.h"
    #include "ui_configtab.h"
    #include "Model/configmodel.h"
    
    
    ConfigTab::ConfigTab(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::ConfigTab),
        m_model(new configModel) //create test model
    {
        ui->setupUi(this);
    
        //load model into tree
        ui->tvListBox->setModel((m_model->getModel()));
    }
    
    ConfigTab::~ConfigTab()
    {
        delete ui;
    }
    

    View/mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
        class MainWindow;
    }
    
    class ConfigTab;
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent=0);
        ~MainWindow();
    
    private:   
        Ui::MainWindow *ui;
        ConfigTab* m_config;
    };
    
    #endif // MAINWINDOW_H
    

    View/mainwindow.cpp

    #include "View\mainwindow.h"
    #include "View\configtab.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        m_config(new ConfigTab(this))
    {
        ui->setupUi(this);
        ui->loConfig->addWidget(m_config);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    main.cpp

    #include "View\mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    Forms/View/configtab.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>ConfigTab</class>
     <widget class="QWidget" name="ConfigTab">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>400</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Form</string>
      </property>
      <layout class="QHBoxLayout" name="horizontalLayout">
       <item>
        <widget class="QTreeView" name="tvListBox"/>
       </item>
       <item>
        <spacer name="horizontalSpacer">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
         <property name="sizeHint" stdset="0">
          <size>
           <width>40</width>
           <height>20</height>
          </size>
         </property>
        </spacer>
       </item>
       <item alignment="Qt::AlignTop">
        <widget class="QPushButton" name="btnAdd">
         <property name="text">
          <string>Add</string>
         </property>
        </widget>
       </item>
       <item alignment="Qt::AlignTop">
        <widget class="QPushButton" name="btnDel">
         <property name="text">
          <string>Remove</string>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
     <resources/>
     <connections/>
    </ui>
    
    

    Forms/View/mainwindow.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>400</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="wdMain">
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <widget class="QTabWidget" name="wdDisplay">
          <property name="currentIndex">
           <number>0</number>
          </property>
          <widget class="QWidget" name="tbConfig">
           <attribute name="title">
            <string>Configure</string>
           </attribute>
           <widget class="QWidget" name="verticalLayoutWidget">
            <property name="geometry">
             <rect>
              <x>0</x>
              <y>10</y>
              <width>371</width>
              <height>191</height>
             </rect>
            </property>
            <layout class="QVBoxLayout" name="loConfig"/>
           </widget>
          </widget>
          <widget class="QWidget" name="tbSettings">
           <attribute name="title">
            <string>Settings</string>
           </attribute>
           <widget class="QWidget" name="verticalLayoutWidget_2">
            <property name="geometry">
             <rect>
              <x>0</x>
              <y>10</y>
              <width>371</width>
              <height>191</height>
             </rect>
            </property>
            <layout class="QVBoxLayout" name="loSettings"/>
           </widget>
          </widget>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QMenuBar" name="menuBar">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>400</width>
         <height>21</height>
        </rect>
       </property>
      </widget>
      <widget class="QToolBar" name="mainToolBar">
       <attribute name="toolBarArea">
        <enum>TopToolBarArea</enum>
       </attribute>
       <attribute name="toolBarBreak">
        <bool>false</bool>
       </attribute>
      </widget>
      <widget class="QStatusBar" name="statusBar"/>
     </widget>
     <layoutdefault spacing="6" margin="11"/>
     <resources/>
     <connections/>
    </ui>
    
    D 1 Reply Last reply 12 Jul 2018, 02:31
    0
    • N NoticeMeSenpai
      12 Jul 2018, 02:18

      Hey all, brand new to both QT as well as C++ and was looking for some assistance with an issue I'm having. Sorry in advance if this is the wrong section of the forum, please let me know where I should direct my post to in that case.

      I'm having an issue with using the QFileSystemModel with the QTreeView widget I have set up in UI. The exact error I get is "invalid use of incomplete type 'class QFileSystemModel'
      ui->tvListBox->setModel((m_model->getModel()));
      ^
      "

      When I compile, I get the following error and am feeling really lost as I don't understand why it won't recognize the QFileSystemModel I set up. It works fine when I use the QFileSystemModel from within the "configTab" class directly but, I'm guessing I goofed at some point when I pushed the actual model into another class named "configModel".

      Here's the full project, in case my code isn't clear https://www.dropbox.com/s/4cm144nkuf1vw4w/Editor.zip?dl=0

      Sorry in advance for the code dump.

      Model/configmodel.h

      #ifndef CONFIGMODEL_H
      #define CONFIGMODEL_H
      #include <QWidget>
      
      class QFileSystemModel;
      class QAbstractItemModel;
      class QDir;
      
      class configModel
      {
      public:
          configModel();
          QFileSystemModel getModel();
      
      private:
          QFileSystemModel *m_fileModel;
      };
      #endif // CONFIGMODEL_H
      

      Model/configmodel.cpp

      #include "configmodel.h"
      #include "QFileSystemModel"
      #include "QDir"
      
      configModel::configModel() :
          m_fileModel(new QFileSystemModel) //create the file model
      {
          //set test model
          m_fileModel->setRootPath(QDir::currentPath());
      }
      
      QFileSystemModel configModel::getModel()
      {
          return m_fileModel;
      }
      

      View/configtab.h

      #ifndef CONFIGTAB_H
      #define CONFIGTAB_H
      
      #include <QWidget>
      
      namespace Ui {
          class ConfigTab;
      }
      
      class configModel;
      
      class ConfigTab : public QWidget
      {
          Q_OBJECT
      
      public:
          explicit ConfigTab(QWidget *parent = 0);
          ~ConfigTab();
      
      private:
          Ui::ConfigTab *ui;
          configModel *m_model;
      };
      
      #endif // CONFIGTAB_H
      

      View/configtab.cpp

      #include "configtab.h"
      #include "ui_configtab.h"
      #include "Model/configmodel.h"
      
      
      ConfigTab::ConfigTab(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::ConfigTab),
          m_model(new configModel) //create test model
      {
          ui->setupUi(this);
      
          //load model into tree
          ui->tvListBox->setModel((m_model->getModel()));
      }
      
      ConfigTab::~ConfigTab()
      {
          delete ui;
      }
      

      View/mainwindow.h

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      
      namespace Ui {
          class MainWindow;
      }
      
      class ConfigTab;
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent=0);
          ~MainWindow();
      
      private:   
          Ui::MainWindow *ui;
          ConfigTab* m_config;
      };
      
      #endif // MAINWINDOW_H
      

      View/mainwindow.cpp

      #include "View\mainwindow.h"
      #include "View\configtab.h"
      #include "ui_mainwindow.h"
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow),
          m_config(new ConfigTab(this))
      {
          ui->setupUi(this);
          ui->loConfig->addWidget(m_config);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      main.cpp

      #include "View\mainwindow.h"
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
      
          return a.exec();
      }
      

      Forms/View/configtab.ui

      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
       <class>ConfigTab</class>
       <widget class="QWidget" name="ConfigTab">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>400</width>
          <height>300</height>
         </rect>
        </property>
        <property name="windowTitle">
         <string>Form</string>
        </property>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <widget class="QTreeView" name="tvListBox"/>
         </item>
         <item>
          <spacer name="horizontalSpacer">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>40</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
         <item alignment="Qt::AlignTop">
          <widget class="QPushButton" name="btnAdd">
           <property name="text">
            <string>Add</string>
           </property>
          </widget>
         </item>
         <item alignment="Qt::AlignTop">
          <widget class="QPushButton" name="btnDel">
           <property name="text">
            <string>Remove</string>
           </property>
          </widget>
         </item>
        </layout>
       </widget>
       <resources/>
       <connections/>
      </ui>
      
      

      Forms/View/mainwindow.ui

      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
       <class>MainWindow</class>
       <widget class="QMainWindow" name="MainWindow">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>400</width>
          <height>300</height>
         </rect>
        </property>
        <property name="windowTitle">
         <string>MainWindow</string>
        </property>
        <widget class="QWidget" name="wdMain">
         <layout class="QVBoxLayout" name="verticalLayout">
          <item>
           <widget class="QTabWidget" name="wdDisplay">
            <property name="currentIndex">
             <number>0</number>
            </property>
            <widget class="QWidget" name="tbConfig">
             <attribute name="title">
              <string>Configure</string>
             </attribute>
             <widget class="QWidget" name="verticalLayoutWidget">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>10</y>
                <width>371</width>
                <height>191</height>
               </rect>
              </property>
              <layout class="QVBoxLayout" name="loConfig"/>
             </widget>
            </widget>
            <widget class="QWidget" name="tbSettings">
             <attribute name="title">
              <string>Settings</string>
             </attribute>
             <widget class="QWidget" name="verticalLayoutWidget_2">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>10</y>
                <width>371</width>
                <height>191</height>
               </rect>
              </property>
              <layout class="QVBoxLayout" name="loSettings"/>
             </widget>
            </widget>
           </widget>
          </item>
         </layout>
        </widget>
        <widget class="QMenuBar" name="menuBar">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>0</y>
           <width>400</width>
           <height>21</height>
          </rect>
         </property>
        </widget>
        <widget class="QToolBar" name="mainToolBar">
         <attribute name="toolBarArea">
          <enum>TopToolBarArea</enum>
         </attribute>
         <attribute name="toolBarBreak">
          <bool>false</bool>
         </attribute>
        </widget>
        <widget class="QStatusBar" name="statusBar"/>
       </widget>
       <layoutdefault spacing="6" margin="11"/>
       <resources/>
       <connections/>
      </ui>
      
      D Offline
      D Offline
      Devopia53
      wrote on 12 Jul 2018, 02:31 last edited by
      #2

      @NoticeMeSenpai

      like this:

      in configtab.cpp
      Add it #include <QFileSystemModel>

      in configmodel.h
      Modify QFileSystemModel *getModel();

      in configmodel.cpp
      Modify QFileSystemModel *configModel::getModel()

      N 1 Reply Last reply 12 Jul 2018, 02:36
      3
      • D Devopia53
        12 Jul 2018, 02:31

        @NoticeMeSenpai

        like this:

        in configtab.cpp
        Add it #include <QFileSystemModel>

        in configmodel.h
        Modify QFileSystemModel *getModel();

        in configmodel.cpp
        Modify QFileSystemModel *configModel::getModel()

        N Offline
        N Offline
        NoticeMeSenpai
        wrote on 12 Jul 2018, 02:36 last edited by
        #3

        @Devopia53

        That worked, thanks so much!

        Let me know if I understand it correctly with the beneath or if I'm wrong somewhere please correct me.

        We include QFileSystemModel into configtab.cpp so that it knows how to handle the dependency of the setModel method.

        We change the getModel method to a pointer of (I actually did not realize you could make a method a pointer lmao) QFileSystemModel because the setModel method requires a pointer and not a direct reference?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jul 2018, 07:53 last edited by
          #4

          Hi,

          You include a header where you actually use a class.

          In your header, as along as you are declaring pointers to the classes you use, you can use forward declaration as you did.

          As for getModel, your original declaration would return an object of type QFileSystemModel. The error you got came from the fact that you were returning an object, therefore, the compiler has to know it and you would have to include the header for that class there. However, even if you added the include, it would not have worked because it is not possible to copy QObject based classes.

          On a side note, you can also make that method const as you are not modifying your class when calling it.

          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
          3

          1/4

          12 Jul 2018, 02:18

          • Login

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