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. QFileDialog has not been declared
Forum Updated to NodeBB v4.3 + New Features

QFileDialog has not been declared

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 15.4k 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.
  • F Offline
    F Offline
    faugra
    wrote on last edited by
    #1

    Hello,

    I'm using Qt 8.4.8 compiled form sources on a Debian linux installation (Linux version 2.6.32-5-amd64 (Debian 2.6.32-46) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4)
    ))

    In QtCreator (version 2.6.1) I'm trying to use the QFileDialog class.

    Here is the code for main.cpp

    @#include "compkit.h"
    #include <QApplication>
    #include <QFileDialog>
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    CompKit w;
    w.show();

    return a.exec();
    }@

    And here is the class code :

    @#include "compkit.h"
    #include "ui_compkit.h"

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

    {
    delete ui;
    }

    void CompKit::on_actionOpen_file_triggered()
    {
    QString fileName;
    fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/home/faugra", tr("Image Files (.)"));
    }@

    The build phase return this error:

    /home/faugra/work/c++/compilatori/ui/compkit/compkit/compkit.cpp:19: error: 'QFileDialog' has not been declared

    I've tried to comment out the #ifndef QT_NO_FILEDIALOG #endif in /usr/local/Trolltech/Qt-4.8.4/QtGui but nothing changed.
    Googling for the issue didn't help. The only information I got was that, in order to reduce library size, the QfileDialog class might have been excluded form the build. I do not know how to check if this is the reason that prevents me to use a QFileDialog object in my project.

    I'm new to Qt, I really like it, but this is a very strange behaviour...

    Thank you in advance for your help!

    f.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      Did you add #include <QFileDialog> in the source code file (.cpp) where you use it ???

      I guess your "class code" is in a separate source code file, but I cannot see the required include there. Including it in your "main.cpp" doesn't help here, because C++ compiles every source code file separately and independently.

      You could put the include statement for QFileDialog into "compkit.h", but it's better to have it in "compkit.cpp" only. If required, you could put a forward declaration into "compkit.h".

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • F Offline
        F Offline
        faugra
        wrote on last edited by
        #3

        Hello MuldeR

        Now it works, I've made a stupid mistake. Thank you very much!

        f.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          Wow, you are using Qt8? We are still waiting for 5 to mature ;)

          Rule of thumb, only include what you need where you need it. And even then, you may face circular dependencies, which happens when two headers include each other, in which case you must do a forward declaration of your class in one of the headers, and include the actual header of the second class in the cpp of the first class. Also, if you have included something in the header, you don't need to include it again in the cpp, since it includes the header and all its includes. If you only need something in the cpp, don't include it in the header, the visibility is one way, the header is visible in the cpp, but the cpp is not visible in the header.

          All of this is one of the reasons many people don't like C++, most other languages don't even have all this stuff to be considered.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            faugra
            wrote on last edited by
            #5

            Thank you utcenter. The Qt version is 4.8.4 of course! :-)

            f.

            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