Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Not Declared In This Scope

    General and Desktop
    2
    3
    4985
    Loading More Posts
    • 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.
    • R
      rabcor last edited by

      I'm trying to write a super basic file manager with QFileSystemModel, but I had barely started before running into compilation errors.

      mainwindow.h

      @#ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QMainWindow>
      #include <QtCore>
      #include <QtGui>
      #include <QFileSystemModel>

      namespace Ui {
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();

      private:
      Ui::MainWindow *ui;
      QFileSystemModel *dirmodel;
      QFileSystemModel *filemodel;

      };

      #endif // MAINWINDOW_H
      @

      main.cpp
      @#include "mainwindow.h"
      #include <QApplication>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      MainWindow w;

      QString sPath = "$HOME/";
      dirmodel = new QFileSystemModel(this);
      dirmodel-> setRootPath(sPath);
      ui->treeView->setModel(dirmodel)
      
      w.show();
      
      return a.exec&#40;&#41;;
      

      }
      @

      Debugger Output
      @-1: In function 'int main(int, char**)':
      10: error: 'dirmodel' was not declared in this scope
      dirmodel = new QFileSystemModel(this);
      ^10: error: invalid use of 'this' in non-member function
      dirmodel = new QFileSystemModel(this);
      ^12: error: 'ui' was not declared in this scope
      ui->treeView->setModel(dirmodel)
      ^@

      Why does it give me these errors? is it something I forgot to include?

      1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators last edited by

        Hi,

        ui is a private member variable of the MainWindow class. You can only access it from one of MainWindow's functions; you cannot access it from the main() function.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply Reply Quote 0
        • R
          rabcor last edited by

          Ah I made a mistake, this was supposed to be in mainwindow.cpp, not main.cpp.

          Thanks :)

          QFileSystemModel doesn't seem to correctly extract icon information from my system so it's only using generic icons for folders and drives (I have this issue with other QT applications that use this class as well)

          How do I make it properly read the icon theme that I am using for other applications? I am on Linux.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post