Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: #include <QString> error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default #include <QString> error

    In a header file included ina an app, the following include compiles:
    Qt Code:
    1. #include <QString>
    To copy to clipboard, switch view to plain text mode 
    In another project, same file, it doesn't.
    Error message is "no such file or directory"
    However, if i put the full pathname and file in place, it compiles.
    Qt Code:
    1. #include "/usr/local/Qt4/include/Qt/qstring.h"
    To copy to clipboard, switch view to plain text mode 

    Why ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: #include <QString> error

    Do you use qmake with both projects?

  3. #3
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    yes, even did them all:
    qmake -project
    qmake
    make clean
    make

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: #include <QString> error

    Did you use the qmake that corresponds to the specific version of Qt that you want to use. For example /usr/local/Qt4/bin/qmake in the latter case because your system may be ending up finding and using your systems Qt3 headers. Maybe you should try to use qmake with its fully qualified path and see what results come out of this.
    /usr/local/Qt4/bin/qmake -project && /usr/local/Qt4/bin/qmake && make.

    p.s. could you please attach the Makefile generated by qmake?
    It has a lot of variables tha state where to find headers and libs.
    Qt Code:
    1. ...
    2. INCPATH = -I/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/include/QtCore -I/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/include/QtCore -I/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/include/QtGui -I/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/include/QtGui -I/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/include -I. -I. -I.
    3. LINK = g++
    4. LFLAGS = -Wl,-rpath,/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/lib
    5. LIBS = $(SUBLIBS) -L/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/lib -lQtGui -L/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/lib -L/usr/X11R6/lib -lpng -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
    6. AR = ar cqs
    7. RANLIB =
    8. QMAKE = /usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/bin/qmake
    9. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by momesana; 28th October 2007 at 07:02.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    What does "qmake -v" output?
    J-P Nurmi

  6. #6
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    Here is some output:

    qmake -v
    QMake version 2.01a
    Using Qt version 4.3.2 in /usr/local/Qt4/lib

    echo $PATH
    /usr/local/Qt4/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

    Qt Code:
    1. TEMPLATE = app
    2. TARGET =
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. ## The following line was manually inserted.
    7. QT = sql gui
    8.  
    9. # Input
    10. HEADERS += areacodescombobox.h clientNotebook.h ../../userFunc.h
    11. FORMS += clientNotebook.ui
    12. SOURCES += areacodescombobox.cpp clientNotebook.cpp main.cpp ../../userFunc.cpp
    To copy to clipboard, switch view to plain text mode 

    Doesn't make any difference if I use full pathname to qmake.
    This is full error message:

    make /usr/local/Qt4/bin/uic clientNotebook.ui -o ui_clientNotebook.h
    Warning: name layoutWidget is already used
    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_SHARED -I/usr/local/Qt4/mkspecs/linux-g++ -I. -I/usr/local/Qt4/include/QtGui -I/usr/local/Qt4/include/QtGui -I/usr/local/Qt4/include/QtSql -I/usr/local/Qt4/include/QtSql -I/usr/local/Qt4/include -I. -I. -I. -o areacodescombobox.o areacodescombobox.cpp
    In file included from ./areacodescombobox.h:10,
    from areacodescombobox.cpp:1:
    ./../../userFunc.h:7:19: error: QString: No such file or directory
    ./../../userFunc.h:8:23: error: QStringList: No such file or directory
    make: *** [areacodescombobox.o] Error 1
    Qt Code:
    1. // areacodescombobox.cpp
    2. #include "./areacodescombobox.h"
    3. ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // areacodescombobox.h
    2. #ifndef AREACODESCOMBOBOX_H
    3. #define AREACODESCOMBOBOX_H
    4.  
    5. //#include <QWidget>
    6. #include <QtSql>
    7. #include <QSqlQuery>
    8. #include <QComboBox>
    9. #include <QApplication>
    10. #include <QMessageBox>
    11. #include "../../userFunc.h"
    12.  
    13. class AreacodesCombobox : public QComboBox
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. AreacodesCombobox(QWidget *parent = 0);
    19. void initializeFields();
    20. void setSelectedLocale(const QString& aSelectedLocale);
    21. void setSelectedAreacode(const QString& aSelectedAreacode);
    22. const QString& selectedLocale() const;
    23. const QString& selectedAreacode() const;
    24.  
    25. private slots:
    26. void on_returnPressed();
    27.  
    28. private:
    29. QString vSelectedLocale;
    30. QString vSelectedAreacode;
    31. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /**************************************************************************
    2. * userFunc.h
    3. * Utility Functions
    4. **************************************************************************/
    5. #ifndef USERFUNC_H
    6. #define USERFUNC_H
    7.  
    8. #include <QString>
    9. #include <QStringList>
    10. //#include "/usr/local/Qt4/include/Qt/qstring.h"
    11. //#include "/usr/local/Qt4/include/Qt/qstringlist.h"
    12.  
    13. QString searchWordsClause( QString, QString, QString, bool, QString );
    14. void addWhereClause( QString &, QString, QString,QString, QString, QString, QString);
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: #include <QString> error

    Do you include userFunc.h from another project's directory (i.e. something outside of your projects root directory) or does it belong to your current project?
    If it is from an outside project you set INCLUDEPATH in your projects .pro file to point to the directory containing the mentioned header and use unqualifiled header includes.
    Qt Code:
    1. INCLUDEPATH += . /path/to/userFunc/
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include <userFunc.h>
    2. instead of
    3. #include <../../userFunc.h>
    To copy to clipboard, switch view to plain text mode 
    Last edited by momesana; 28th October 2007 at 08:23.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    It should be:
    QT = core sql gui
    or simply
    QT += sql
    (core and gui modules are enabled by default).
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    vieraci (28th October 2007)

  10. #9
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    Quote Originally Posted by jpn View Post
    It should be:

    or simply

    (core and gui modules are enabled by default).
    Thanks jpn,
    That fixed the problem I started with, now I'm left with the other problem I just posted.

  11. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    I suppose you should add areacodescombobox.h and areacodescombobox.cpp to clientNotebook.pro.
    J-P Nurmi

  12. #11
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    Quote Originally Posted by jpn View Post
    I suppose you should add areacodescombobox.h and areacodescombobox.cpp to clientNotebook.pro.
    It is already. Look at posted code above.

  13. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    Quote Originally Posted by vieraci View Post
    It is already. Look at posted code above.
    Oh, I thought you said it was a plugin.. Anyway, did you actually implement a function body for AreacodesCombobox constructor?
    J-P Nurmi

  14. #13
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    The current project is a plugin of the main app,
    the main app is in
    projects/thisProject/src
    the plugin is in
    projects/thisProject/src/notebooks/clientNotebook

    I tried your suggestion, no different.

    Some more information:
    The areacodesCombobox is a promoted QcomboBox widget in the clientNotebook widget.
    If I use the full pathname to QString and compile, I get a different error. Don't know if this is important or just confuses things even more...

    clientNotebook.o: In function `Ui_ClientNotebook::setupUi(QWidget*)':
    clientNotebook.cpp.text._ZN17Ui_ClientNotebook7setupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0xf23): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)'
    clientNotebook.cpp.text._ZN17Ui_ClientNotebook7setupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0x3211): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)'
    clientNotebook.cpp.text._ZN17Ui_ClientNotebook7setupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0x37d7): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)'
    collect2: ld returned 1 exit status
    make: *** [clientNotebook] Error 1

  15. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    • Do you actually have a plugin interface, declared with Q_DECLARE_INTERFACE()?
    • Is the plugin exported with Q_EXPORT_PLUGIN2() macro?
    • Are you compiling it as static or dynamic plugin?
    • Are you using QPluginLoader to load it?

    Perhaps you should take one of plugin examples as an implementation base?

    That's how I implemented my first plugin. I took plug & paint as base and rewrote it to my needs. That way you'll get a working set of project files for starters.
    J-P Nurmi

  16. #15
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    I'll have a good read...

  17. #16
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    After reading up on plugins, my project was correct. However what I'm building is a Qt Designer plugin, not a dynamic or static runtime plugin.

    On a closer read of the error message:
    clientNotebook.o: In function `Ui_ClientNotebook::setupUi(QWidget*)':
    clientNotebook.cpp.text._ZN17Ui_ClientNotebook7setupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0xf23): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)
    Providing a default constructor resolved it.
    So it appears that the compiler didn't add a default constructor.

  18. #17
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    Quote Originally Posted by vieraci View Post
    Providing a default constructor resolved it.
    So it appears that the compiler didn't add a default constructor.
    Like I said, "C++ compilers provide a default constructor in case you don't provide one. But in case you declare anything, you must also implement it".
    J-P Nurmi

  19. #18
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    Yes you were right, but I don't understand why a constructor wasn't declared by the compiler here ??
    Last edited by vieraci; 29th October 2007 at 07:41.

  20. #19
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QString> error

    Because you told compiler that you want to implement it yourself
    Qt Code:
    1. class AreacodesCombobox : public QComboBox
    2. {
    3. public:
    4. AreacodesCombobox(QWidget *parent = 0); // <-- "hey compiler, i want to implement constructor myself!"
    5. ...
    6. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  21. #20
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QString> error

    D...uuuuuhhhh... of course !! one can be really stupid at times.

Similar Threads

  1. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.