make και C++ (ή QT)

malos | Κυρ, 08/09/2009 - 13:58 | 5' | 4

Καλησπέρα παίδες !
Βρήκα ένα Hello world σε C++ . Το άλλαξα λίγο για να έχω βάλει κάτι δικό μου και να καταννοώ πράγματα σιγά σιγά.
Ο κώδικάς του είναι :

 

#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QLineEdit>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QWidget *window = new QWidget();
QVBoxLayout *layout = new QVBoxLayout();
QLabel *label = new QLabel("H TAMPELLA EDO !!!");
QPushButton *button = new QPushButton("KLEISE");

QLineEdit *Edit = new QLineEdit("As grapso kai do kati");
QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit()));

layout->addWidget(label);
layout->addWidget(button);
layout->addWidget(Edit);

window->setLayout(layout);

window->show();
return app.exec();
}

 Αυτό που πρόσθεσα είναι το Line Edit και το ονόμασα Edit πιο κάτω και χάρηκα που το όρισα σωστά (έβαλα και τη γραμμή layout->addWidget(Edit); και μου δούλεψε.
Δόυλεψε όμως στην Ultimate 2.2 . Έδωσα από τερματικό : qmake -project και έφτιαξε αρχείο .pro, μετά έδωσα qmake και έφτιαξε το Makefile και μετά make και έφτιαξε το εκτελέσιμο όπου με κλικ άνοιξε κανονικά το παραθυράκι.
Στην κανονική όμως ubuntu 9.04 το make μου έβγαζε error. Μήπως λείπουν πακέτα ; Ή τι άλλο μπορεί να συμβαίνει ;

Αυτό μου βγάζει

 

pal@malos:~/Επιφάνεια εργασίας/ss$ make

g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/share/qt3/include -o hello.o hello.cpp
hello.cpp:1:24: error: QApplication: No such file or directory
hello.cpp:2:18: error: QLabel: No such file or directory
hello.cpp:3:23: error: QPushButton: No such file or directory
hello.cpp:4:23: error: QVBoxLayout: No such file or directory
hello.cpp:5:21: error: QLineEdit: No such file or directory
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:8: σφάλμα: ‘QApplication’ was not declared in this scope
hello.cpp:8: σφάλμα: expected `;' before ‘app’
hello.cpp:10: σφάλμα: ‘QWidget’ was not declared in this scope
hello.cpp:10: σφάλμα: ‘window’ was not declared in this scope
hello.cpp:10: σφάλμα: expected type-specifier before ‘QWidget’
hello.cpp:10: σφάλμα: expected `;' before ‘QWidget’
hello.cpp:11: σφάλμα: ‘QVBoxLayout’ was not declared in this scope
hello.cpp:11: σφάλμα: ‘layout’ was not declared in this scope
hello.cpp:11: σφάλμα: expected type-specifier before ‘QVBoxLayout’
hello.cpp:11: σφάλμα: expected `;' before ‘QVBoxLayout’
hello.cpp:12: σφάλμα: ‘QLabel’ was not declared in this scope
hello.cpp:12: σφάλμα: ‘label’ was not declared in this scope
hello.cpp:12: σφάλμα: expected type-specifier before ‘QLabel’
hello.cpp:12: σφάλμα: expected `;' before ‘QLabel’
hello.cpp:13: σφάλμα: ‘QPushButton’ was not declared in this scope
hello.cpp:13: σφάλμα: ‘button’ was not declared in this scope
hello.cpp:13: σφάλμα: expected type-specifier before ‘QPushButton’
hello.cpp:13: σφάλμα: expected `;' before ‘QPushButton’
hello.cpp:15: σφάλμα: ‘QLineEdit’ was not declared in this scope
hello.cpp:15: σφάλμα: ‘Edit’ was not declared in this scope
hello.cpp:15: σφάλμα: expected type-specifier before ‘QLineEdit’
hello.cpp:15: σφάλμα: expected `;' before ‘QLineEdit’
hello.cpp:16: σφάλμα: ‘QObject’ has not been declared
hello.cpp:16: σφάλμα: ‘clicked’ was not declared in this scope
hello.cpp:16: σφάλμα: ‘SIGNAL’ was not declared in this scope
hello.cpp:16: σφάλμα: ‘app’ was not declared in this scope
hello.cpp:16: σφάλμα: ‘quit’ was not declared in this scope
hello.cpp:16: σφάλμα: ‘SLOT’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:7: προειδοποίηση: unused parameter ‘argc’
hello.cpp:7: προειδοποίηση: unused parameter ‘argv’
make: *** [hello.o] Error 1
pal@malos:~/Επιφάνεια εργασίας/ss$

 

Δώσε αστέρια!

MO: (ψήφοι: 0)

Σχόλια

Δοκίμασε πρώτα το εύκολο:

Δώσε ένα make clean και μετά qmake (ή qmake-qt4 αν χρησιμοποιείς qt4 κι έχεις και τις 2 εκδόσεις εγκατεστημένες) και make από την αρχή μπας και στρώσει.

Γενικά, καλό είναι αυτή η διαδικασία να γίνεται κάθε φορά. Μπορείς να φτιάξεις κι ένα σκριπτάκι:

#! /bin/bash
 
make clean
rm εκτελέσιμο
rm Makefile
 
qmake-qt4 εκτελέσιμο.pro
make
 
./εκτελέσιμο

Όχι δεν στρώνει. Το κάνω αυτό που λες 3 μέρες τώρα.

Μάλλον λείπει κάποιο  πακέτο

Λογικά, αν έχεις το "build essential" και με τα libqtgui4, libqtcore4 και qt4-dev-tools δεν χρειάζεσαι τίποτα παραπάνω.