Anmelden

Archiv verlassen und diese Seite im Standarddesign anzeigen : QApplication wird nicht gefunden



Eagle
14-03-2008, 15:51
Hallo,

ich möchte mich in QT4 einlernen und habe folgendes Beispiel


#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}

Die Projektdatei sieht so aus:

################################################## ####################
# Automatically generated by qmake (1.07a) Fri Mar 14 14:29:51 2008
################################################## ####################

TEMPLATE = app
CONFIG -= moc
INCLUDEPATH += .

# Input
SOURCES += hello.cpp

und das Makefile

################################################## ###########################
# Makefile for building: hello
# Generated by qmake (1.07a) (Qt 3.3.7) on: Fri Mar 14 14:30:47 2008
# Project: hello.pro
# Template: app
# Command: $(QMAKE) -o Makefile hello.pro
################################################## ###########################

####### Compiler, tools and options

CC = gcc
CXX = g++
LEX = flex
YACC = yacc
CFLAGS = -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT
CXXFLAGS = -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT
LEXFLAGS =
YACCFLAGS= -d
INCPATH = -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/share/qt3/include
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS) -L/usr/share/qt3/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm -lpthread
AR = ar cqs
RANLIB =
MOC = /usr/share/qt3/bin/moc
UIC = /usr/share/qt3/bin/uic
QMAKE = qmake
TAR = tar -cf
GZIP = gzip -9f
COPY = cp -f
COPY_FILE= $(COPY)
COPY_DIR = $(COPY) -r
INSTALL_FILE= $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = rm -f
SYMLINK = ln -sf
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p

####### Output directory

OBJECTS_DIR = ./

####### Files

HEADERS =
SOURCES = hello.cpp
OBJECTS = hello.o
FORMS =
UICDECLS =
UICIMPLS =
SRCMOC =
OBJMOC =
DIST = hello.pro
QMAKE_TARGET = hello
DESTDIR =
TARGET = hello

first: all
####### Implicit rules

.SUFFIXES: .c .o .cpp .cc .cxx .C

.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<

####### Build rules

all: Makefile $(TARGET)

$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) $(LIBS)

mocables: $(SRCMOC)
uicables: $(UICDECLS) $(UICIMPLS)

$(MOC):
( cd $(QTDIR)/src/moc && $(MAKE) )

Makefile: hello.pro /usr/share/qt3/mkspecs/default/qmake.conf
$(QMAKE) -o Makefile hello.pro
qmake:
@$(QMAKE) -o Makefile hello.pro

dist:
@mkdir -p .tmp/hello && $(COPY_FILE) --parents $(SOURCES) $(HEADERS) $(FORMS) $(DIST) .tmp/hello/ && ( cd `dirname .tmp/hello` && $(TAR) hello.tar hello && $(GZIP) hello.tar ) && $(MOVE) `dirname .tmp/hello`/hello.tar.gz . && $(DEL_FILE) -r .tmp/hello

mocclean:

uiclean:

yaccclean:
lexclean:
clean:
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core


####### Sub-libraries

distclean: clean
-$(DEL_FILE) $(TARGET) $(TARGET)


FORCE:

####### Compile

hello.o: hello.cpp

####### Install

install:

uninstall:



Wenn ich jetzt make ausführe, bekomme ich diese Fehlermeldungen:

hello.cpp:1:24: error: QApplication: Datei oder Verzeichnis nicht gefunden
hello.cpp:2:18: error: QLabel: Datei oder Verzeichnis nicht gefunden
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:6: error: ‘QApplication’ was not declared in this scope
hello.cpp:6: error: expected `;' before ‘app’
hello.cpp:7: error: ‘QLabel’ was not declared in this scope
hello.cpp:7: error: ‘label’ was not declared in this scope
hello.cpp:7: error: expected type-specifier before ‘QLabel’
hello.cpp:7: error: expected `;' before ‘QLabel’
hello.cpp:9: error: ‘app’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:4: warning: unused parameter ‘argc’
hello.cpp:4: warning: unused parameter ‘argv’
make: *** [hello.o] Fehler 1

Ganz kapiere ich das nicht, denn QApplikation liegt hier:

-rw-r--r-- 1 root root 13162 2008-02-26 18:27 /usr/include/qt4/QtGui/qapplication.h

Vielleicht könnt ihr mir auf die Sprünge helfen?

Grüsse

Eagle

locus vivendi
14-03-2008, 16:15
Das Makefile ist für Qt3. Du benutzt Qmake von Qt3. Das Problem wird möglicherweise verschwinden wenn du Qmake von Qt4 benutzt.

Eagle
14-03-2008, 16:41
Bingo!!

Vielen Dank, das war's. In dem Buch steht leider nur

qmake -project
qmake hello.pro

Mit qmake-qt4
klappt es dann!

Grüsse

Eagle

peschmae
14-03-2008, 20:26
Das ist auch nicht der Fehler des Buchs, qmake von Qt4 heisst eigentlich immer qmake.

Ausser wenn die Distribution das umbenannt hat - wie bei Debian/Ubuntu der Fall. Dort kannst du via den alternatives-Mechanismus auswählen, welches der beiden QMakes jetzt bei einem Aufruf von "qmake" an der Reihe ist:

sid:/home/peschmae# update-alternatives --config qmake

Es gibt nur 1 Programm, welches qmake bereitstellt
(/usr/bin/qmake-qt4). Nichts zu konfigurieren.
sid:/home/peschmae#


Geht bei mir jetzt natürlich nicht weiter weil ich ausschliesslich das QMake von Qt4 installiert habe ;)

MfG Peschmä