Compiling QT4 Code using cmake 2.6
Hi Guys!
I have a big Problem. I want to compile my Source Code with Cmake, because later I must add another lib and that isn't possible with qmake.
First here the Code:
widget.h
Code:
#define _WIDGET_H_
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QWidget>
#include <QtGui>
Q_OBJECT
public:
private:
int richt[3][200];
int counter;
//QLabel *bla;
//QPushButton *subsampling;
//QLabel *fertig;
public slots:
void copy_list();
};
widget.cpp:
Code:
#include "widget.h"
#include <QtGui>
#include <QHeaderView>
#include <QTableWidget>
MyWidget
::MyWidget(QWidget *parent
){
//Attribute
counter=0;
//Attributen-Zuweisungen
lineEdit_v->setMaximumSize( 210, lineEdit_v->maximumSize().height() );
lineEdit_l->setMaximumSize( 210, lineEdit_l->maximumSize().height() );
lineEdit_ru->setMaximumSize( 210, lineEdit_ru->maximumSize().height() );
//Anpassung des QTableWidgets
//
//Ueberschrift
fonts << "Speed" << "Drehung" << "Dauer";
tablewidget->setHorizontalHeaderLabels(fonts);
//SIGNALS AND SLOTS
connect(send, SIGNAL(clicked()),this , SLOT(copy_list()));
//LAYOUT
drehung->addWidget(label_l);
drehung->addWidget(lineEdit_l);
vor->addWidget(label_v);
vor->addWidget(lineEdit_v);
dauer->addWidget(label_ru);
dauer->addWidget(lineEdit_ru);
linkespalte->addLayout(vor);
linkespalte ->addLayout(drehung);
linkespalte->addLayout(dauer);
linkespalte->addWidget(send);
center->addLayout(linkespalte);
center->addStretch();
end->addLayout(center);
end->addWidget(tablewidget);
this->setLayout(end);
}
void MyWidget::copy_list(){
QString speed
= lineEdit_v
->text
();
QString dauer
= lineEdit_ru
->text
();
tablewidget->setItem(counter, 0, newItem);
tablewidget->setItem(counter, 1, degree);
tablewidget->setItem(counter, 2, time);
counter++;
}
main.cpp
Code:
#include "widget.h"
#include <QtGui>
#include <QHeaderView>
#include <QTableWidget>
int main(int argc, char *argv[])
{
MyWidget widget;
widget.show();
return app.exec();
}
And at last but not least the CMakeLists.txt
Code:
cmake_minimum_required(VERSION 2.6)
FIND_PACKAGE(Qt4)
SET(QT_USE_QTXML 1)
INCLUDE(${QT_USE_FILE})
QT4_AUTOMOC(main.cpp widget.cpp widget.h)
ADD_EXECUTABLE(myexe main.cpp widget.cpp)
TARGET_LINK_LIBRARIES(myexe ${QT_LIBRARIES})
I have all the files in a folder. In the console, I am typing:
"cmake-2.6 ."
Code:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - found
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - not found.
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found.
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found.
-- Found Qt-Version 4.4.2
-- Found OpenSSL: /usr/lib/libssl.so
-- Looking for _POSIX_TIMERS
-- Looking for _POSIX_TIMERS - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/serenity/RoboGui
okay, all fine until now.
then I must make it:
typing:
"make"
Code:
Scanning dependencies of target myexe
[ 50%] Building CXX object CMakeFiles/myexe.dir/main.cpp.o
[100%] Building CXX object CMakeFiles/myexe.dir/widget.cpp.o
Linking CXX executable myexe
CMakeFiles/myexe.dir/main.cpp.o: In function `MyWidget::~MyWidget()':
main.cpp:(.text._ZN8MyWidgetD1Ev[MyWidget::~MyWidget()]+0xf): undefined reference to `vtable for MyWidget'
main.cpp:(.text._ZN8MyWidgetD1Ev[MyWidget::~MyWidget()]+0x19): undefined reference to `vtable for MyWidget'
CMakeFiles/myexe.dir/widget.cpp.o: In function `MyWidget::MyWidget(QWidget*)':
widget.cpp:(.text+0x2ef): undefined reference to `vtable for MyWidget'
widget.cpp:(.text+0x2f9): undefined reference to `vtable for MyWidget'
CMakeFiles
/myexe.
dir/widget.
cpp.
o: In function `MyWidget
::MyWidget(QWidget*)':widget.cpp:(.text+0xf1b): undefined reference to `vtable for MyWidget'
CMakeFiles/myexe.dir/widget.cpp.o:widget.cpp:(.text+0xf25): more undefined references to `vtable for MyWidget' follow
CMakeFiles/myexe.dir/widget.cpp.o: In function `MyWidget::tr(char const*, char const*)':
widget.cpp:(.text._ZN8MyWidget2trEPKcS1_[MyWidget::tr(char const*, char const*)]+0x1e): undefined reference to `MyWidget::staticMetaObject'
collect2: ld gab 1 als Ende-Status zurück
make[2]: *** [myexe] Fehler 1
make[1]: *** [CMakeFiles/myexe.dir/all] Fehler 2
make: *** [all] Fehler 2
Where is the problem and why couldn't I compile my program? ("Fehler" means error)
I also testet it with qmake and it works. But I have to do it with cmake.
Greetings
Serenity
Re: Compiling QT4 Code using cmake 2.6
I don't know the effect of QT4_AUTOMOC call but in CMake docs I've found
Quote:
macro QT4_AUTOMOC(sourcefile1 sourcefile2 ... )
This macro is still experimental.
It can be used to have moc automatically handled.
So if you have the files foo.h and foo.cpp, and in foo.h a
a class uses the Q_OBJECT macro, moc has to run on it. If you don't
want to use QT4_WRAP_CPP() (which is reliable and mature), you can insert
#include "foo.moc"
in foo.cpp and then give foo.cpp as argument to QT4_AUTOMOC(). This will the
scan all listed files at cmake-time for such included moc files and if it finds
them cause a rule to be generated to run moc at build time on the
accompanying header file foo.h.
If a source file has the SKIP_AUTOMOC property set it will be ignored by this macro.
You have to put
Code:
#include "widget.moc"
in the widget.cpp file and remove widget.h as parameter of QT4_AUTOMOC
See http://http://wiki.qtcentre.org/inde...pps_with_CMake
that suggest the use of QT4_WRAP_CPP instead of QT4_AUTOMOC.
In your widget.h file you have to insert
as first line and
Code:
#endif // _WIDGET_H_
as last line of code