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. Not Declared In This Scope
Forum Updated to NodeBB v4.3 + New Features

Not Declared In This Scope

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.6k 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.
  • R Offline
    R Offline
    rabcor
    wrote on last edited by
    #1

    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
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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
      0
      • R Offline
        R Offline
        rabcor
        wrote on last edited by
        #3

        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
        0

        • Login

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