<<精通QT4编程>>中的IDE是kdevelop,照书中的第一个例子始终编译有问题,可能是kedevelop设置问题,在Develop中编译运行正常,在终端上编译也正常,代码如下:
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include <QtCore/QTextCodec>
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QWidget* pWidget = new QWidget;
QLabel label(pWidget);
label.setText(QObject::tr("同一个世界,同一个梦想!"));
QPushButton* btn = new QPushButton(QObject::tr("关闭"), pWidget);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(&label);
layout->addWidget(btn);
pWidget->setLayout(layout);
QObject::connect(btn, SIGNAL(clicked()), pWidget, SLOT(close()));
pWidget->show();
return app.exec();
}
编译信息:
cd '/hello' && LC_MESSAGES="C" LC_CTYPE="C" gmake -k clean && LC_MESSAGES="C" LC_CTYPE="C" gmake -k
cd src/ && gmake -f Makefile clean
rm -f main.o
rm -f *~ core *.core
cd src/ && gmake -f Makefile
compiling main.cpp (g++)
linking ../bin/hello (g++)
main.o: In function `main':
main.cpp:(.text+0x31): undefined reference to `QApplication::QApplication(int&, char**, int)'
main.cpp:(.text+0x95): undefined reference to `QWidget::QWidget(QWidget*, QFlags<Qt::WindowType>)'
main.cpp:(.text+0xb2): undefined reference to `QLabel::QLabel(QWidget*, QFlags<Qt::WindowType>)'
main.cpp:(.text+0xe7): undefined reference to `QLabel::setText(QString const&)'
main.cpp:(.text+0x143): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
main.cpp:(.text+0x171): undefined reference to `QVBoxLayout::QVBoxLayout()'
main.cpp:(.text+0x196): undefined reference to `QBoxLayout::addWidget(QWidget*, int, QFlags<Qt::AlignmentFlag>)'
main.cpp:(.text+0x1b8): undefined reference to `QBoxLayout::addWidget(QWidget*, int, QFlags<Qt::AlignmentFlag>)'
main.cpp:(.text+0x1c4): undefined reference to `QWidget::setLayout(QLayout*)'
main.cpp:(.text+0x1fd): undefined reference to `QApplication::exec()'
main.cpp:(.text+0x20a): undefined reference to `QLabel::~QLabel()'
main.cpp:(.text+0x215): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0x231): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0x252): undefined reference to `QLabel::~QLabel()'
collect2: ld returned 1 exit status
gmake[1]: *** [../bin/hello] Error 1
gmake[1]: Target `first' not remade because of errors.
gmake: *** [sub-src-make_default] Error 2
gmake: Target `first' not remade because of errors.
*** Exited with status: 2 ***
说明:在我的FC8下终端 kdevelop --version
Qt: 3.3.8b
KDE: 3.5.9-5.fc8 Fedora
KDevelop: 3.5.2
可是我也在建工程的时候设置了Q4的qmake和design路径了阿
高手指点下!