Qt/CallANormalFunction
From ProgrammingExamples
< Qt
CallAFunction.cpp
#include <qpushbutton.h> #include <qapplication.h> #include "Foo.h" void MyFunction() { std::cout << "hi" << std::endl; } int main(int argc, char **argv) { QApplication a(argc, argv); Foo foo; QPushButton myButton( "Click me", 0); QObject::connect(&myButton, SIGNAL(clicked()), &foo, SLOT(bar())); myButton.show(); return a.exec(); }
foo.h
#ifndef FOO_HPP #define FOO_HPP #include <qobject.h> #include <iostream> void MyFunction(); class Foo : public QObject { Q_OBJECT public slots: void bar() { MyFunction(); } }; #endif // FOO_HPP
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(CallAFunction) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) QT4_WRAP_CPP(MOCSrcs Foo.h) ADD_EXECUTABLE(CallAFunction CallAFunction.cpp ${MOCSrcs} ) #this does not work #ADD_EXECUTABLE(CallAFunction CallAFunction.cpp Foo.h) TARGET_LINK_LIBRARIES(CallAFunction ${QT_LIBRARIES})