This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KAppTemplate CMake Qt-C++ sample won't build, missing moc

Tags: None
(comma "," separated)
jerol
Registered Member
Posts
2
Karma
0
Hi. I'm very much a novice C++ programmer. I've never used an IDE before today, and I've never written a graphical application. I decided upon KDevelop because I'd like to try writing a Qt app for my KDE desktop. I know nothing about Qt yet, very little about KDevelop, and nothing at all about CMake or any other type of make utility. I mention all this in hopes that anyone who can help me will not presuppose that I know what I'm doing. :)

I wanted to try compiling a simple Qt graphical "Hello World" program. Using KAppTemplate, I chose the CMake Qt-C++ template to generate a CMake/Qt4 based GUI application. It appeared to generate properly. After importing it into KDevelop, I tried to build it. I got an error because of a missing moc file. I don't know what a moc file is, so I don't know how to fix it.

KDevelop is version 4.3.1, using KDE Development Platform 4.8.5. My KDE version is 4.8.5.

Code: Select all
/home/s/src/mffv/build> /usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug /home/s/src/mffv/
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- 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 Qt4: /usr/bin/qmake (found version "4.8.2")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/s/src/mffv/build

/home/s/src/mffv/build> make
[ 33%] Generating mffv.moc
/home/s/src/mffv/mffv.h:1: Parse error at ""
make[2]: *** [mffv.moc] Error 1
make[1]: *** [CMakeFiles/mffv.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***


So it seems that KDevelop runs make, which starts to generate the moc file, then encounters a parse error that halts the generation of the moc. Looking in the .cpp and .h files, I cannot see what the problem could be. This code is untouched by me; it is exactly as generated by KAppTemplate.

This is the cpp file that includes the header file and the moc file.

Code: Select all
#include "mffv.h"

#include <QtGui/QLabel>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QAction>

%{APPNAMEID}::%{APPNAMEID}()
{
    QLabel* l = new QLabel( this );
    l->setText( "Hello World!" );
    setCentralWidget( l );
    QAction* a = new QAction(this);
    a->setText( "Quit" );
    connect(a, SIGNAL(triggered()), SLOT(close()) );
    menuBar()->addMenu( "File" )->addAction( a );
}

%{APPNAMEID}::~%{APPNAMEID}()
{}

#include "mffv.moc"


This is the header file.

Code: Select all
#ifndef %{APPNAMEID}_H
#define %{APPNAMEID}_H

#include <QtGui/QMainWindow>

class %{APPNAMEID} : public QMainWindow
{
Q_OBJECT
public:
    %{APPNAMEID}();
    virtual ~%{APPNAMEID}();
};

#endif // %{APPNAMEID}_H


I don't find a moc file anywhere in the project build directory. There are some errors in the CMakeError.log file, but it doesn't refer to the moc, and the errors in it seem related to the Q_WS_WIN, Q_WS_QWS, and Q_WS_MAC, which were all listed in the build messages as "not found".

Can anyone help me understand what the problem is, and how to fix it?
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Hello!

The .moc files are generated by Qt's meta object compiler (moc). They are used by Qt for some things like signals and slots. Those files are generated at compile-time and are not (and should not be) included in the template. The error you have is the moc failing to generate the file (that's the
Code: Select all
[ 33%] Generating mffv.moc
/home/s/src/mffv/mffv.h:1: Parse error at ""
stuff). Which is not very surprising considering what the files look like -- look at all those %{APPNAMEID} markers! They should have been replaced with your application name when you created the template, but apparently were not.

In any case I'd advise you to update to KDevelop 4.5 -- years of improvement have gone into it, including a new template engine which will quite certainly fix the issue you're facing ;)
This is also the reason there's probably no point to report a bug about this -- KDevelop 4.3 is old, and the component the error appears in has been replaced.
To fix this particular instance of the problem, replace all the %{APPNAMEID} markers with your application name (e.g. "myapp") and recompile.

Cheers,
Sven


I'm working on the KDevelop IDE.
jerol
Registered Member
Posts
2
Karma
0
Sven, thank you very much. I replaced %{APPNAMEID} with the application name everywhere that it occurred, and now it builds successfully.

When I click the Execute button, it says "No valid executable specified", so there is still something wrong. But at least I got past the build error.

I'll upgrade to 4.5 before I try anything else.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Good idea.

If it still fails after that, look at Run -> Configure launches. Probably you don't have a proper configuration there for launching your application.

Cheers,
Sven


I'm working on the KDevelop IDE.


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], Sogou [Bot]