PDA

View Full Version : About QUiLoader, Connect, Q_Object and 'undefined reference to `vtable for wrun' '



tonnot
5th October 2010, 08:05
I want to have a simple ui loader and the posibility to connect signals from ui to slots stored in MyClass. (wrun)

For example, I would can connect them with this code .

QList<QPushButton *> pbto = formWidget->findChildren<QPushButton *>();
for (int i=0;i<pbto.count();i++)
{
connect(pbto.at(i), SIGNAL(clicked()), this, SLOT(button_click));
}

To do this :
1.- I have to use Q_Object macro
2.- I have to subclass Qobject

When I compile I have get errors : 'undefined reference to `vtable for wrun' ' at the lines (in cpp) where is placed :
wrun.cpp:11: undefined reference to `vtable for wrun'
wrun.cpp:11: undefined reference to `vtable for wrun'
debug/wrun.o: In function `~wrun':
wrun.cpp:13: undefined reference to `vtable for wrun'
wrun.cpp:13: undefined reference to `vtable for wrun'
wrun.cpp:13: undefined reference to `vtable for wrun'

Can anyone help me ?

wrun.h

class wrun : public QObject
{
Q_OBJECT

public:
wrun();
~wrun();
....

wrun.cpp

#include "wrun.h"
#include <QUiLoader>

wrun::wrun(){}

wrun::~wrun(){}
....




Any idea ?

Lykurg
5th October 2010, 08:21
rerun qmake since you probably included the Q_OBJECT macro later.

ChrisW67
5th October 2010, 08:22
For later: your connect should probably be:

connect(pbto.at(i), SIGNAL(clicked()), this, SLOT(button_click())); Note the extra parentheses.

tonnot
5th October 2010, 08:39
Thanks
Yes ! As simple as rebuild .... (and I already knew I had and extra parenthesis)

This kind of things are those that perplex me
Althought is another question but... anyone can indicate me a link about make, cmake, qmake, etc ?
(really I dont understand nothing about it, by the moment QT are doing all for me but I dont understand what's happen when compile)

youarefunny
28th May 2011, 21:57
cmake has a good basic tutorial on it's website. Also if you google compiling Qt with cmake I found a really useful tutorial. I used it in part to get my cmake file.

My CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

PROJECT(MarkTracker)

FILE(GLOB MarkTracker_SOURCES *.cpp)
FILE(GLOB MarkTracker_HEADERS *.hpp)

FILE(GLOB MarkTracker_UI *.ui)

configure_file ("${PROJECT_SOURCE_DIR}/info.h.in" "${PROJECT_BINARY_DIR}/info.h") # Makes info.h which has some marcos in it.

FIND_PACKAGE(Qt4 REQUIRED)
SET(QT_USE_QTUITOOLS TRUE) # QtUiTools is for dynamic form loading
INCLUDE(${QT_USE_FILE}) # Include the files Qt needs
ADD_DEFINITIONS(${QT_DEFINITIONS}) # Define the things Qt needs defined

QT4_WRAP_UI(MarkTracker_UI_HEADERS ${MarkTracker_UI}) # Genertate ui_*.h files from .ui files
QT4_WRAP_CPP(MarkTracker_HEADERS_MOC ${MarkTracker_HEADERS}) # Send our headers through the moc

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(marktracker
${MarkTracker_SOURCES}
${MarkTracker_HEADERS_MOC}
${MarkTracker_UI_HEADERS}
)
TARGET_LINK_LIBRARIES(marktracker ${QT_LIBRARIES})
FILE(COPY resources DESTINATION .) # Get our resources file location