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. How to extend QFileSystemModel (inheritance)
QtWS25 Last Chance

How to extend QFileSystemModel (inheritance)

Scheduled Pinned Locked Moved General and Desktop
qfilesystemmodeinheritance
9 Posts 3 Posters 3.6k 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.
  • VandiV Offline
    VandiV Offline
    Vandi
    wrote on last edited by
    #1

    Hello,

    I am trying to create a class that inherits from QFileSystemModel.
    I tried to create a Shared Library to expose the QFileSystemModel overrided methods, but several linking errors were shown.
    I want to do that without recompiling the whole Qt source-code. The main goal is to dynamically link the extended class. Is that possible?

    Here is the error message:
    ...
    qremotestoragemodel3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QFileSystemModel::QFileSystemModel(class QObject *)" (_imp??0QFileSystemModel@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall QRemoteStorageModel3::QRemoteStorageModel3(class QObject *)" (??0QRemoteStorageModel3@@QAE@PAVQObject@@@Z)
    ...

    Any suggestion?

    Thanks.

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

      Hi and welcome to devnet,

      Can you show your code ?

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

      VandiV 1 Reply Last reply
      1
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Seems your shared library is not linked to the Qt libraries. Are you linking it to the widgets module?

        VandiV 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi and welcome to devnet,

          Can you show your code ?

          VandiV Offline
          VandiV Offline
          Vandi
          wrote on last edited by
          #4

          @SGaist I appreciate the community is very active here, thanks.

          Here is my code:

          // main.cpp
          #include <QCoreApplication>
          #include "qremotestoragemodel3.h"

          int main(int argc, char *argv[])
          {
          QCoreApplication a(argc, argv);
          QRemoteStorageModel3 *qmi = new QRemoteStorageModel3();
          //QModelIndex qModelIndex;
          //qmi->remove(qModelIndex);
          printf(qmi->getString());
          return a.exec();
          }

          //qremotestoragemodel3.cpp
          #include "qremotestoragemodel3.h"

          QT_BEGIN_NAMESPACE

          #ifndef QT_NO_FILESYSTEMMODEL

          //constructor
          QRemoteStorageModel3::QRemoteStorageModel3(QObject *parent) : QFileSystemModel(parent){
          }

          //Just to test the compilation
          char *QRemoteStorageModel3 :: getString(){
          return "a";
          }

          //Trying to re-implement the remove method from QFileSystemModel
          bool QRemoteStorageModel3 :: remove(const QModelIndex &index)
          {
          printf("Hello world!! \n");

          //Old remove() code from QFileSystemModel
          /* 
          

          const QString path = filePath(aindex);
          QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
          #ifndef QT_NO_FILESYSTEMWATCHER
          d->fileInfoGatherer.removePath(path);
          #endif
          if (QFileInfo(path).isFile())
          return QFile::remove(path);
          return QDir(path).removeRecursively();
          */

          return true;
          

          }
          #endif
          QT_END_NAMESPACE

          //qremotestoragemodel3.h
          #ifndef QREMOTESTORAGEMODEL3_H
          #define QREMOTESTORAGEMODEL3_H

          #include <QtCore/qglobal.h>
          #include <QtWidgets/qfilesystemmodel.h>

          QT_BEGIN_NAMESPACE

          class QRemoteStorageModel3: public QFileSystemModel{

          public:
          explicit QRemoteStorageModel3(QObject *parent = 0);
          char *getString();
          bool remove(const QModelIndex &index);
          };

          QT_END_NAMESPACE

          #endif // QREMOTESTORAGEMODEL3_H

          1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            Seems your shared library is not linked to the Qt libraries. Are you linking it to the widgets module?

            VandiV Offline
            VandiV Offline
            Vandi
            wrote on last edited by
            #5

            @Chris-Kawa Hi Chris, I just posted my code here.
            I am not sure if I have to do something in my code in order to link to the Qt libraries, or is it something in the project properties?
            Thank you for your attention.

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

              From your code, it looks like you are mixing subclassing for your project and subclassing to add a new class in Qt's source.

              If you only want to create a new subclass do not copy code from Qt's implementation like that. Just write your code and call the base class implementation when needed.

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

              VandiV 1 Reply Last reply
              1
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                It depends on your build system. By the look of the message you're using compiler from Visual Studio.

                If you're building from within Qt Creator using qmake then you need to make sure the .pro file contains this:

                QT += gui widgets
                

                If you're building from within Visual Studio using the VS Add-in then right click on the project in the solution explorer, select Qt Project Settings and on the Qt Modules tab make sure GUI and Widgets are selected.

                VandiV 1 Reply Last reply
                1
                • SGaistS SGaist

                  From your code, it looks like you are mixing subclassing for your project and subclassing to add a new class in Qt's source.

                  If you only want to create a new subclass do not copy code from Qt's implementation like that. Just write your code and call the base class implementation when needed.

                  VandiV Offline
                  VandiV Offline
                  Vandi
                  wrote on last edited by
                  #8

                  @SGaist Thank you. I am studying more about how to create a new subclass. In fact, I don't want to call the base class implementation, I just want to re-implement it, because the FileSystemModel class deals with the local file system, and I want my subclass to inherit from FilesystemModel but my implementation will deal with remote file systems.
                  Thank you again.

                  1 Reply Last reply
                  0
                  • Chris KawaC Chris Kawa

                    It depends on your build system. By the look of the message you're using compiler from Visual Studio.

                    If you're building from within Qt Creator using qmake then you need to make sure the .pro file contains this:

                    QT += gui widgets
                    

                    If you're building from within Visual Studio using the VS Add-in then right click on the project in the solution explorer, select Qt Project Settings and on the Qt Modules tab make sure GUI and Widgets are selected.

                    VandiV Offline
                    VandiV Offline
                    Vandi
                    wrote on last edited by
                    #9

                    @Chris-Kawa I am building from within Qt Creator (Windows 7), my .pro file didn't contain that! it just had:

                    QT += gui

                    Thank you Chris.

                    1 Reply Last reply
                    0

                    • Login

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