PDA

View Full Version : #include <QString> error



vieraci
28th October 2007, 07:08
In a header file included ina an app, the following include compiles:


#include <QString>

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.


#include "/usr/local/Qt4/include/Qt/qstring.h"


Why ?

momesana
28th October 2007, 07:11
Do you use qmake with both projects?

vieraci
28th October 2007, 07:24
yes, even did them all:
qmake -project
qmake
make clean
make

momesana
28th October 2007, 07:54
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.


...
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.
LINK = g++
LFLAGS = -Wl,-rpath,/usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/lib
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
AR = ar cqs
RANLIB =
QMAKE = /usr/local/Trolltech/Qt-4.4.0-snapshot-20071021/bin/qmake
...

jpn
28th October 2007, 08:57
What does "qmake -v" output?

vieraci
28th October 2007, 09:12
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



TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

## The following line was manually inserted.
QT = sql gui

# Input
HEADERS += areacodescombobox.h clientNotebook.h ../../userFunc.h
FORMS += clientNotebook.ui
SOURCES += areacodescombobox.cpp clientNotebook.cpp main.cpp ../../userFunc.cpp


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




// areacodescombobox.cpp
#include "./areacodescombobox.h"
...




// areacodescombobox.h
#ifndef AREACODESCOMBOBOX_H
#define AREACODESCOMBOBOX_H

//#include <QWidget>
#include <QtSql>
#include <QSqlQuery>
#include <QComboBox>
#include <QApplication>
#include <QMessageBox>
#include "../../userFunc.h"

class AreacodesCombobox : public QComboBox
{
Q_OBJECT

public:
AreacodesCombobox(QWidget *parent = 0);
void initializeFields();
void setSelectedLocale(const QString& aSelectedLocale);
void setSelectedAreacode(const QString& aSelectedAreacode);
const QString& selectedLocale() const;
const QString& selectedAreacode() const;

private slots:
void on_returnPressed();

private:
QString vSelectedLocale;
QString vSelectedAreacode;
};





/************************************************** ************************
* userFunc.h
* Utility Functions
************************************************** ************************/
#ifndef USERFUNC_H
#define USERFUNC_H

#include <QString>
#include <QStringList>
//#include "/usr/local/Qt4/include/Qt/qstring.h"
//#include "/usr/local/Qt4/include/Qt/qstringlist.h"

QString searchWordsClause( QString, QString, QString, bool, QString );
void addWhereClause( QString &, QString, QString,QString, QString, QString, QString);

#endif

momesana
28th October 2007, 09:19
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.


INCLUDEPATH += . /path/to/userFunc/





#include <userFunc.h>
instead of
#include <../../userFunc.h>

jpn
28th October 2007, 09:31
It should be:

QT = core sql gui
or simply

QT += sql
(core and gui modules are enabled by default).

vieraci
28th October 2007, 09:35
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_ClientNotebook7s etupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0xf23): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)'
clientNotebook.cpp:(.text._ZN17Ui_ClientNotebook7s etupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0x3211): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)'
clientNotebook.cpp:(.text._ZN17Ui_ClientNotebook7s etupUiEP7QWidget[Ui_ClientNotebook::setupUi(QWidget*)]+0x37d7): undefined reference to `AreacodesCombobox::AreacodesCombobox(QWidget*)'
collect2: ld returned 1 exit status
make: *** [clientNotebook] Error 1

vieraci
28th October 2007, 09:44
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.

jpn
28th October 2007, 09:57
I suppose you should add areacodescombobox.h and areacodescombobox.cpp to clientNotebook.pro.

vieraci
28th October 2007, 10:10
I suppose you should add areacodescombobox.h and areacodescombobox.cpp to clientNotebook.pro.

It is already. Look at posted code above.

jpn
28th October 2007, 10:14
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?

vieraci
28th October 2007, 10:27
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:



void AreacodesCombobox::initializeFields()
{
QString blank = " ";
setSelectedAreacode(blank);
setSelectedLocale(blank);
clear();
}

void AreacodesCombobox::on_returnPressed()
{
QString aLocale=currentText();
if ((aLocale.trimmed().length() > 1) && (aLocale != QString(selectedLocale()).toUpper()))
{
QString searchText= ("UCASE(locale) like '%");
searchText.append(aLocale.trimmed().toUpper());
searchText.append("%' order by LOCALE");
QString clause = searchWordsClause(aLocale, "locale", "AND", false,"locale");
clause.prepend("SELECT Areacode, Locale FROM AreacodesView WHERE ");
clause.append(" Order by Locale");
QSqlQuery query(clause);
if (query.isActive()) // successful execution
{
if (query.size()==0)
{
QApplication::beep ();
QMessageBox::warning(this, tr("Postcode Search"),
tr("No match found.\nCheck the spelling and try again."), QMessageBox::Ok);
setFocus();
}
else
{
clear();
while (query.next())
{
QString locale = query.value(0).toString();
addItem(locale);
}
if (query.size()==1)
QComboBox::setCurrentIndex(1);
else
{
// comboBox()->select(1, true);
QComboBox::showPopup();
}
}
}
else
{
QApplication::beep ();
QMessageBox::warning(this, tr("SQL Error"),
query.lastError().text(), QMessageBox::Ok);
}
// else if (model->query().isSelect()) // is a select statement
}
}

jpn
28th October 2007, 10:44
Yes the notebook part IS a plugin
But template is "app" and it has main()..?


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:


AreacodesCombobox::AreacodesCombobox(QWidget *parent) : QComboBox(parent)
{
// ...
}



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().

vieraci
28th October 2007, 11:17
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.


C++ compilers provide a default constructor in case you don't provide one. But in case you declare anything, you must also implement it:


AreacodesCombobox::AreacodesCombobox(QWidget *parent) : QComboBox(parent)
{
// ...
}


But do I really need a constructor here ? there's nothing special I need to implement there, I'm just adding custom code.


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.



#include "./areacodescombobox.h"
/*
AreacodesCombobox::AreacodesCombobox()
{
}
*/
const QString& AreacodesCombobox::selectedLocale() const
{
return vSelectedLocale;
}

void AreacodesCombobox::setSelectedLocale(const QString& aSelectedLocale)
{
if (!(vSelectedLocale == aSelectedLocale))
{
vSelectedLocale = aSelectedLocale;
}
}

const QString& AreacodesCombobox::selectedAreacode() const
{
return vSelectedAreacode;
}

void AreacodesCombobox::setSelectedAreacode(const QString& aSelectedAreacode)
{
if (!(vSelectedAreacode == aSelectedAreacode))
{
vSelectedAreacode = aSelectedAreacode;
}
}
...

vieraci
28th October 2007, 11:54
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. :(

jpn
28th October 2007, 12:22
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?

Echo Plugin Example (http://doc.trolltech.com/4.3/tools-echoplugin.html)
Plug & Paint Example (http://doc.trolltech.com/4.3/tools-plugandpaint.html)

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.

vieraci
28th October 2007, 12:36
I'll have a good read...

vieraci
29th October 2007, 00:34
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_ClientNotebook7s etupUiEP7QWidget[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.
:o

jpn
29th October 2007, 07:58
Providing a default constructor resolved it.
So it appears that the compiler didn't add a default constructor.
:o
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".

vieraci
29th October 2007, 08:29
Yes you were right, but I don't understand why a constructor wasn't declared by the compiler here ??

jpn
29th October 2007, 09:29
Because you told compiler that you want to implement it yourself :)


class AreacodesCombobox : public QComboBox
{
public:
AreacodesCombobox(QWidget *parent = 0); // <-- "hey compiler, i want to implement constructor myself!"
...
};

vieraci
29th October 2007, 09:44
D...uuuuuhhhh... of course !! one can be really stupid at times.

jpn
29th October 2007, 09:47
Heh, it's sometimes surprisingly easy to become blind at your own code. ;)