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

Thread: #include <QString> error

  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 08: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 09: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

    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

  11. #10
    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.

  12. #11
    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

  13. #12
    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.

  14. #13
    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

  15. #14
    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 the notebook part IS a plugin, and no, I didn't provide a constructor. I thought a default constructor might be provided by Qt... I just implemented the extra functions I need for the comboBox.

    The .h file is in this post, this is the cpp file:

    Qt Code:
    1. void AreacodesCombobox::initializeFields()
    2. {
    3. QString blank = " ";
    4. setSelectedAreacode(blank);
    5. setSelectedLocale(blank);
    6. clear();
    7. }
    8.  
    9. void AreacodesCombobox::on_returnPressed()
    10. {
    11. QString aLocale=currentText();
    12. if ((aLocale.trimmed().length() > 1) && (aLocale != QString(selectedLocale()).toUpper()))
    13. {
    14. QString searchText= ("UCASE(locale) like '%");
    15. searchText.append(aLocale.trimmed().toUpper());
    16. searchText.append("%' order by LOCALE");
    17. QString clause = searchWordsClause(aLocale, "locale", "AND", false,"locale");
    18. clause.prepend("SELECT Areacode, Locale FROM AreacodesView WHERE ");
    19. clause.append(" Order by Locale");
    20. QSqlQuery query(clause);
    21. if (query.isActive()) // successful execution
    22. {
    23. if (query.size()==0)
    24. {
    25. QApplication::beep ();
    26. QMessageBox::warning(this, tr("Postcode Search"),
    27. tr("No match found.\nCheck the spelling and try again."), QMessageBox::Ok);
    28. setFocus();
    29. }
    30. else
    31. {
    32. clear();
    33. while (query.next())
    34. {
    35. QString locale = query.value(0).toString();
    36. addItem(locale);
    37. }
    38. if (query.size()==1)
    39. QComboBox::setCurrentIndex(1);
    40. else
    41. {
    42. // comboBox()->select(1, true);
    43. QComboBox::showPopup();
    44. }
    45. }
    46. }
    47. else
    48. {
    49. QApplication::beep ();
    50. QMessageBox::warning(this, tr("SQL Error"),
    51. query.lastError().text(), QMessageBox::Ok);
    52. }
    53. // else if (model->query().isSelect()) // is a select statement
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 

  16. #15
    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
    Yes the notebook part IS a plugin
    But template is "app" and it has main()..?

    Quote Originally Posted by vieraci View Post
    and no, I didn't provide a constructor. I thought a default constructor might be provided by Qt... I just implemented the extra functions I need for the comboBox.
    C++ compilers provide a default constructor in case you don't provide one. But in case you declare anything, you must also implement it:
    Qt Code:
    1. AreacodesCombobox::AreacodesCombobox(QWidget *parent) : QComboBox(parent)
    2. {
    3. // ...
    4. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by vieraci View Post
    The .h file is in this post, this is the cpp file:
    In case that's really the full .cpp, looks like you're missing implementations of a bunch of other functions as well; setSelectedLocale(), setSelectedAreacode(), selectedLocale(), selectedAreacode().
    J-P Nurmi

  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

    Quote Originally Posted by jpn View Post
    But template is "app" and it has main()..?
    I created it by followed the example in the docs, now I can't find it, but from memory there was a "main" and template was "app"...but that probably doesn't mean it's correct.

    Quote Originally Posted by jpn View Post
    C++ compilers provide a default constructor in case you don't provide one. But in case you declare anything, you must also implement it:
    Qt Code:
    1. AreacodesCombobox::AreacodesCombobox(QWidget *parent) : QComboBox(parent)
    2. {
    3. // ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    But do I really need a constructor here ? there's nothing special I need to implement there, I'm just adding custom code.

    Quote Originally Posted by jpn View Post
    In case that's really the full .cpp, looks like you're missing implementations of a bunch of other functions as well; setSelectedLocale(), setSelectedAreacode(), selectedLocale(), selectedAreacode().
    Yes, they're implemented, seems I didn't select the whole file when I copied.
    I actually was going to implement a constructor but thought about what I needed to do that was different, answer was "nothing" so I rem-ed it out.

    Qt Code:
    1. #include "./areacodescombobox.h"
    2. /*
    3. AreacodesCombobox::AreacodesCombobox()
    4. {
    5. }
    6. */
    7. const QString& AreacodesCombobox::selectedLocale() const
    8. {
    9. return vSelectedLocale;
    10. }
    11.  
    12. void AreacodesCombobox::setSelectedLocale(const QString& aSelectedLocale)
    13. {
    14. if (!(vSelectedLocale == aSelectedLocale))
    15. {
    16. vSelectedLocale = aSelectedLocale;
    17. }
    18. }
    19.  
    20. const QString& AreacodesCombobox::selectedAreacode() const
    21. {
    22. return vSelectedAreacode;
    23. }
    24.  
    25. void AreacodesCombobox::setSelectedAreacode(const QString& aSelectedAreacode)
    26. {
    27. if (!(vSelectedAreacode == aSelectedAreacode))
    28. {
    29. vSelectedAreacode = aSelectedAreacode;
    30. }
    31. }
    32. ...
    To copy to clipboard, switch view to plain text mode 

  18. #17
    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

    So changing TEMPLATE = lib compiles ok, but a simmilar error message appears when I move into the plugin dir and attempt to make the plugin.

  19. #18
    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

  20. #19
    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...

  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

    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.

Similar Threads

  1. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 03: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, 13:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 25th August 2006, 00:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 13:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 13: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.