PDA

View Full Version : qt3 using cmake simple application question (problem solved)



zl2k
2nd September 2008, 04:29
Problem solved. It should be

class WindowBase : public QMainWindow
instead of

class WindowBase : private QMainWindow
Thanks to CMake mail list.

hi, there

I need to write an application in qt3 with cmake and here is my very beginning:
just display a mainwindow and nothing else (the mainwindow is produced
by qt designer windowbase.ui ) I have my own reason to do it in qt3
not in qt4 (for thumbnail view).

During compiling, I get:
-----------------------------
windowbase.h

class WindowBase : private QMainWindow }{...}
-----------------------------

-----------------------------
windowbase.cxx
-----------------------------

I manually create the following files:

window.h


#ifndef WINDOW_H
#define WINDOW_H
#include "windowbase.h"

class Window : private WindowBase{
public: //nothing else
public slots: //nothing else
};
#endif

window.cpp

#include "window.h"
// nothing else

main.cpp

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
#include "window.h"
#include <qmainwindow.h>

int main(int argc, char *argv[])
{
QApplication myApp(argc,argv);
Window * mypWindow = new Window();
myApp.setMainWidget(mypWindow); //error here, line 23
mypWindow->show();
return myApp.exec();
return EXIT_SUCCESS;
}

The CMakeLists.txt is as following (I highly suspect something wrong
here, I stitched the script but not sure what I am doing. And I can't
find any example related to qt3 + cmake + ui anywhere)


PROJECT(study3)

SET(CMAKE_VERBOSE_MAKEFILE ON)
ADD_DEFINITIONS(-Wall -O2)

FIND_PACKAGE(Qt3 REQUIRED)
ADD_DEFINITIONS(${QT_DEFINITIONS})

INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}
${QT_INCLUDE_DIR}
${QT_INCLUDE_PATH}
)

SET(STUDY3_UI_SRC
windowbase.ui
)

SET(STUDY3_SOURCES
window.cpp main.cpp
)

QT_WRAP_UI(study3 STUDY3_UI_H STUDY3_UI_CPP ${STUDY3_UI_SRC})
QT_WRAP_CPP(study3 STUDY3_UI_CPP ${STUDY3_UI_H})

# I am not sure where and how or if I need to put "moc" somewhere

INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

ADD_EXECUTABLE(study3
${STUDY3_SOURCES}
${STUDY3_UI_CPP}
)

TARGET_LINK_LIBRARIES(study3 ${QT_LIBRARIES} png jpeg)

Here is the error message I got during compile:


/study3/main.cpp:23: error: 'QWidget' is an inaccessible base of 'Window'
/usr/share/qt3/include/qmainwindow.h:98: error: 'virtual void
QMainWindow::show()' is inaccessible
/study3/main.cpp:24: error: within this context
/study3/main.cpp:24: error: 'QMainWindow' is not an accessible base of 'Window'

But, if I change the line 23 into


WindowBase * mypWindow = new WindowBase();

then the program can compile and runs fine.

The Window class inherits from WindowBase and I am suppose to do my
own stuff there (in current case I do nothing). What's wrong with my
code? Thanks for your comments.

zl2k