[Solved] "QTableWidgetItem: No such file or directory" in Qt 5



  • Greetings.

    I just installed Qt 5, specifically Qt 5.0.1 for 32-bit Windows (MinGW 4.7, 823 MB). Download it from http://qt-project.org/downloads.

    The entire installation process went well and achieved successfully execute several ejmplos demonstration.

    However, when I try to run a program spreadsheet that I made some time ago (this is really an example program that appears in the book "C + + GUI Programming with Qt 4" which I completed), I get the following error message :

    "QTableWidgetItem: No such file or directory"

    Even for other sample programs that I did get this error message:

    "QtGui / Application: No such file or directory"

    All these programs ran perfectly when I wrote and run using QtSDK 1.2.1 (which was the version of Qt that was using until now to install Qt 5).

    So what is the problem or that you need:

    • I did the installation wrong?

    • I need to do something else after installation? (I just follow the installation wizard)

    • How do I fix this problem? ... Should I change any environment variable?

    Right.
    As always thanks in advance for any responses and/or comments


  • Lifetime Qt Champion

    Hi,

    Is QT += widgets missing in your pro file ?



  • Yeah, that line was missing (with the version of Qt that I was working previously did not need to add that line ... I guess it's something new in Qt 5).

    I added the line and the error no longer appears, but now are many others who do not really understand.

    In the header file of one of my classes I have several "forward declarations":

    QCheckBox class;
    QLabel class;
    QLineEdit class;
    QPushButton class;

    Apparently these are generating errors.

    Specifically, I get:

    invalid use of incomplete type 'class QLabel'
    C: \ Users \ PROJECT \ Documents \ files - isaac \ examples Qt \ findDialog \ finddialog.cpp: 10: error: invalid use of incomplete type 'class QLabel'

    forward declaration of 'class QLabel
    C: \ Users \ PROJECT \ Documents \ files - isaac \ examples Qt \ findDialog \ finddialog.h: 14: error: forward declaration of 'class QLabel'

    Similarly for the other classes shown above.

    In the corresponding .cpp file, I only included the head <QtGui>.


  • Lifetime Qt Champion

    QtGui is Qt 4 and you should avoid using it anyway. That pulls a whole lot of unused includes (which must be parsed and thus slow down the compilation time)

    Simply add the includes for all your forward declared class and you'll be good



  • Thank you very much, I solved the problem.

    However, I noticed that I had to include a number of header files in first I thought they were not needed.

    For example (just to name one), in my class 'MainWindow' (which is a subclass of QMainWindow) I had to include:

    <QMenuBar> (I guess because I call the function 'menuBar ()').
    <QStatusBar> (I guess because I call the function 'statusBar ()').

    I thought:
    To include "MainWindow.h" (which includes <QMainWindow>) should be enough, or am I wrong?.

    I supposed that this is how it works Qt5?, Or else:
    Is there a problem with my installation Qt5 or my program?


  • Lifetime Qt Champion

    You're welcome !

    You are wrong, QMainWindow does also make use of forward declarations. You only need to include the headers for the stuff you use.

    It's not the way Qt 5 works and your installation is fine. It's the fact that you were including QtGui that pulls Everything from the QtGui module. It's useful when writing a quick test application but good code practice tells that you only include what you use (also for compilation performance reason)

    Don't forget to update the thread's title to solved so other forum users may know that a solution has been found :)



  • Indeed, this spreadsheet application was one of the first applications that I wrote when I was just starting with Qt (now I have a little more knowledge, but I'm still a newbie in Qt).

    It was only a sample application that was all by using to test my installation of Qt5.

    Well, to sum (actually, to see if I understood well what you trying to say):

    • You need to include the headers <QStatusBar>, <QMenuBar> and other, even if already been included <QMainWindow> (in fact I had to include those in my class 'MainWindow', which inherits from QMainWindow)

    • According to the above... my installation of Qt5 is okay.

    Please excuse the inconvenience.


  • Lifetime Qt Champion

    If you take a look at the QMainWindow header, you'll see that it includes only QWidget and QTabWidget, the rest is only forward declaration, which is why you have to #include <QStatusBar> when you want to call statusBar() and use the returned QStatusBar.

    • So: no, you have to include them when they are not already included in an other header AND that you need to instantiate an object, use an object, a static function or an enum from that class. Thus if you only have pointers i.e QMenuBar *menuBar(), use forward declarations and #include <QMenuBar>
      in your implementation file.

    • Yes, indeed

    No excuse to give, it's always good searching to understand what you are using :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.