Qt-interest Archive, August 2007
connect problems: "no such slot" and base class
Message 1 in thread
I'm trying to get the hang out of Qt and right now I've hit a small bump in
the road.
I've created a .ui file through Qt Designer and followed the multiple
inheritance approach from the "Compile Time Form Processing" section of Qt
Designer's manual. Then I've added a protected slot to the child class and
proceeded to try to connect a signal from a UI component to that particular
slot. The code compiles but when I run the app, I get the following output:
<output>
Object::connect: No such slot QMainWindow::connection()
Object::connect: (sender name: 'actionConnect')
Object::connect: (receiver name: 'MainWindowy')
</output>
The code is as follows:
<declaration>
#include <QMainWindow>
#include "ui_MainWindow.h"
class MainWindow :
public QMainWindow,
private Ui::MainWindowy
{
// snip
public:
MainWindow();
~MainWindow();
protected slots:
void connection();
// snip
};
</declaration>
<implementation>
#include "mainwindow.hpp"
MainWindow::MainWindow()
: QMainWindow( NULL )
{
setupUi( this );
// signals and slots
connect(actionConnect, SIGNAL(triggered(bool)), SLOT(connection()));
}
MainWindow::~MainWindow() {}
void MainWindow::connection()
{
}
</implementation>
So,what am I missing? Why is QObject::connect pointing to the QMainWindow
class instead of the MainWindow class?
Thanks in advance
Rui Maciel
--
[ signature omitted ]
Message 2 in thread
Hi,
Rui Maciel wrote:
> <declaration>
> #include <QMainWindow>
> #include "ui_MainWindow.h"
>
>
> class MainWindow :
> public QMainWindow,
> private Ui::MainWindowy
> {
> // snip
> public:
> MainWindow();
> ~MainWindow();
>
> protected slots:
> void connection();
>
> // snip
> };
> </declaration>
>
> So,what am I missing? Why is QObject::connect pointing to the QMainWindow
> class instead of the MainWindow class?
Your declaration should have Q_OBJECT at the top i.e.
class MainWindow :
public QMainWindow,
private Ui::MainWindowy
{
Q_OBJECT
// snip
public:
MainWindow();
~MainWindow();
...
Tim
--
[ signature omitted ]
Message 3 in thread
Tim Dewhirst wrote:
> Your declaration should have Q_OBJECT at the top i.e.
>
> class MainWindow :
> public QMainWindow,
> private Ui::MainWindowy
> {
> Q_OBJECT
> // snip
> public:
> MainWindow();
> ~MainWindow();
> ...
I've added the Q_OBJECT at the top but when I compiled, I got a flurry of
error messages. The error messages are as following:
<output>
mainwindow.o: In function `MainWindow::~MainWindow()':
mainwindow.cpp:(.text+0x24): undefined reference to `vtable for MainWindow'
mainwindow.cpp:(.text+0x2c): undefined reference to `vtable for MainWindow'
mainwindow.o: In function `MainWindow::~MainWindow()':
mainwindow.cpp:(.text+0xb4): undefined reference to `vtable for MainWindow'
mainwindow.cpp:(.text+0xbc): undefined reference to `vtable for MainWindow'
mainwindow.o: In function `MainWindow::~MainWindow()':
mainwindow.cpp:(.text+0x144): undefined reference to `vtable for MainWindow'
mainwindow.o:mainwindow.cpp:(.text+0x14c): more undefined references to
`vtable for MainWindow' follow
collect2: ld returned 1 exit status
make[1]: *** [../bin/direqtchat] Error 1
</output>
The error messages persist even after cleaning the entire project and
compiling everything from scratch.
What else am I missing?
Thanks!
Rui Maciel
--
[ signature omitted ]
Message 4 in thread
On 26.08.07 22:30:07, Rui Maciel wrote:
> Tim Dewhirst wrote:
> > Your declaration should have Q_OBJECT at the top i.e.
> > class MainWindow :
> > public QMainWindow,
> > private Ui::MainWindowy
> > {
> > Q_OBJECT
> > // snip
> > public:
> > MainWindow();
> > ~MainWindow();
> > ...
>
>
> I've added the Q_OBJECT at the top but when I compiled, I got a flurry of
> error messages. The error messages are as following:
>
> <output>
> mainwindow.o: In function `MainWindow::~MainWindow()':
> mainwindow.cpp:(.text+0x24): undefined reference to `vtable for MainWindow'
> mainwindow.cpp:(.text+0x2c): undefined reference to `vtable for MainWindow'
> mainwindow.o: In function `MainWindow::~MainWindow()':
> mainwindow.cpp:(.text+0xb4): undefined reference to `vtable for MainWindow'
> mainwindow.cpp:(.text+0xbc): undefined reference to `vtable for MainWindow'
> mainwindow.o: In function `MainWindow::~MainWindow()':
> mainwindow.cpp:(.text+0x144): undefined reference to `vtable for MainWindow'
> mainwindow.o:mainwindow.cpp:(.text+0x14c): more undefined references to
> `vtable for MainWindow' follow
> collect2: ld returned 1 exit status
> make[1]: *** [../bin/direqtchat] Error 1
> </output>
>
> The error messages persist even after cleaning the entire project and
> compiling everything from scratch.
>
> What else am I missing?
What buildsystem are you using? It seems that whatever system you use
(seemingly not qmake) it doesn't run moc on your .h files, which is
needed for some of the QObject magic to work. For autotools projects
you need a #include "mainwindow.moc" in your mainwindow.cpp, for cmake
system you need that as well and a call to qt4_automoc() giving it the
sources of your app (macro name may be slightly different).
Andreas
--
[ signature omitted ]
Message 5 in thread
Andreas Pakulat wrote:
> What buildsystem are you using? It seems that whatever system you use
> (seemingly not qmake) it doesn't run moc on your .h files, which is
> needed for some of the QObject magic to work. ÂFor autotools projects
> you need a #include "mainwindow.moc" in your mainwindow.cpp, for cmake
> system you need that as well and a call to qt4_automoc() giving it the
> sources of your app (macro name may be slightly different
After reading your post (and Tim's) I went digging to see what caused the
problem. I'm using KDevelop and sometimes things don't quite work with that
IDE. So, to make a long story short, I was trying to build a Qt4 project
with Qt3 tools. So naturally things got a bit flaky.
After rewiring some symbolic links, things work smoothly.
Thanks for the help. Kudos!
Rui Maciel
--
[ signature omitted ]
Message 6 in thread
On 28.08.07 12:22:23, Rui Maciel wrote:
> Andreas Pakulat wrote:
>
> > What buildsystem are you using? It seems that whatever system you use
> > (seemingly not qmake) it doesn't run moc on your .h files, which is
> > needed for some of the QObject magic to work. For autotools projects
> > you need a #include "mainwindow.moc" in your mainwindow.cpp, for cmake
> > system you need that as well and a call to qt4_automoc() giving it the
> > sources of your app (macro name may be slightly different
>
>
> After reading your post (and Tim's) I went digging to see what caused the
> problem. I'm using KDevelop and sometimes things don't quite work with that
> IDE. So, to make a long story short, I was trying to build a Qt4 project
> with Qt3 tools. So naturally things got a bit flaky.
>
> After rewiring some symbolic links, things work smoothly.
Thats not needed at all. All you have to do with recent KDevelop
releases is choose the right qmake under Project Options->C++
Support->Qt (yes I know the place is a bit unfortunate). That is of
course if you really use qmake as buildsystem.
Andreas
--
[ signature omitted ]
Message 7 in thread
Andreas Pakulat wrote:
> Thats not needed at all. All you have to do with recent KDevelop
> releases is choose the right qmake under Project Options->C++
> Support->Qt (yes I know the place is a bit unfortunate). That is of
> course if you really use qmake as buildsystem.
Unfortunately I had that option taken cared of from the project start and
selecting qmake-qt4 wasn't enough to avoid that vtable problem. On the
other hand, relinking uic to uic-qt4, which was linked to uic-qt4, appeared
to solved it.
Rui Maciel
--
[ signature omitted ]
Message 8 in thread
Rui Maciel wrote:
> relinking uic to uic-qt4, which was linked to uic-qt4,
Obviously, it was linked to uic-qt3. Damned lazy eye :o)
Rui Maciel
--
[ signature omitted ]
Message 9 in thread
On 28.08.07 18:33:53, Rui Maciel wrote:
> Andreas Pakulat wrote:
>
> > Thats not needed at all. All you have to do with recent KDevelop
> > releases is choose the right qmake under Project Options->C++
> > Support->Qt (yes I know the place is a bit unfortunate). That is of
> > course if you really use qmake as buildsystem.
>
> Unfortunately I had that option taken cared of from the project start and
> selecting qmake-qt4 wasn't enough to avoid that vtable problem.
Well, unless you change the .pro file via an editor or the QMake Manager
you'd have to re-run qmake recursively on your project to get updated
Makefile's after switching the qmake binary (so if for some reason you
once ran qmake on your project and it was qt3 qmake you need to run
qmake from qt4 again on it to get proper Makefiles).
I did heavy testing with this stuff in a mixed environment (Qt4 and Qt3
from Debian and a self-built version from KDE's svn) and never ran into
a situation where such a broken Makefile wasn't repaired by an explicit
run of qmake (available in the context menu of the QMake manager).
Andreas
--
[ signature omitted ]
Message 10 in thread
Andreas Pakulat wrote:
> Well, unless you change the .pro file via an editor or the QMake Manager
> you'd have to re-run qmake recursively on your project to get updated
> Makefile's after switching the qmake binary (so if for some reason you
> once ran qmake on your project and it was qt3 qmake you need to run
> qmake from qt4 again on it to get proper Makefiles).
I've specified the qmake binary as being qmake-qt4 at the start of the
project, before I ran the first build. It has been configured that way from
the start.
> I did heavy testing with this stuff in a mixed environment (Qt4 and Qt3
> from Debian and a self-built version from KDE's svn) and never ran into
> a situation where such a broken Makefile wasn't repaired by an explicit
> run of qmake (available in the context menu of the QMake manager).
My guess is that qmake wasn't the culprit here but uic. Everything compiled
smoothly once I relinked uic to point to uic-qt4 instead of uic-qt3.
Unfortunately KDevelop doesn't have any option covering that.
Best regards
Rui Maciel
--
[ signature omitted ]
Message 11 in thread
On 29.08.07 14:57:05, Rui Maciel wrote:
> Andreas Pakulat wrote:
>
> > Well, unless you change the .pro file via an editor or the QMake Manager
> > you'd have to re-run qmake recursively on your project to get updated
> > Makefile's after switching the qmake binary (so if for some reason you
> > once ran qmake on your project and it was qt3 qmake you need to run
> > qmake from qt4 again on it to get proper Makefiles).
>
> I've specified the qmake binary as being qmake-qt4 at the start of the
> project, before I ran the first build. It has been configured that way from
> the start.
>
> > I did heavy testing with this stuff in a mixed environment (Qt4 and Qt3
> > from Debian and a self-built version from KDE's svn) and never ran into
> > a situation where such a broken Makefile wasn't repaired by an explicit
> > run of qmake (available in the context menu of the QMake manager).
>
> My guess is that qmake wasn't the culprit here but uic. Everything compiled
> smoothly once I relinked uic to point to uic-qt4 instead of uic-qt3.
> Unfortunately KDevelop doesn't have any option covering that.
Because KDevelop has no control over the uic-run that is done when
building the project. The reason is simply that qmake is responsible to
create a Makefile that calls uic and I can't remember a breakage in the
Debian packages where qmake-qt4 produced a Makefile that had uic and not
uic-qt4 in it.
Andreas
--
[ signature omitted ]
Message 12 in thread
Hi,
Rui Maciel wrote:
> I've added the Q_OBJECT at the top but when I compiled, I got a flurry of
> error messages. The error messages are as following:
>
> <output>
> mainwindow.o: In function `MainWindow::~MainWindow()':
> mainwindow.cpp:(.text+0x24): undefined reference to `vtable for MainWindow'
> mainwindow.cpp:(.text+0x2c): undefined reference to `vtable for MainWindow'
> mainwindow.o: In function `MainWindow::~MainWindow()':
> mainwindow.cpp:(.text+0xb4): undefined reference to `vtable for MainWindow'
> mainwindow.cpp:(.text+0xbc): undefined reference to `vtable for MainWindow'
> mainwindow.o: In function `MainWindow::~MainWindow()':
> mainwindow.cpp:(.text+0x144): undefined reference to `vtable for MainWindow'
> mainwindow.o:mainwindow.cpp:(.text+0x14c): more undefined references to
> `vtable for MainWindow' follow
> collect2: ld returned 1 exit status
> make[1]: *** [../bin/direqtchat] Error 1
> </output>
>
> The error messages persist even after cleaning the entire project and
> compiling everything from scratch.
>
> What else am I missing?
Hmmm. You do say you did a clean build, but it looks like a stale
makefile or similar i.e. moc is not being run for mainwindow.cpp.
Tim
--
[ signature omitted ]
Message 13 in thread
On Aug 26, 2007, at 10:21 PM, Rui Maciel wrote:
> I'm trying to get the hang out of Qt and right now I've hit a small
> bump in
> the road.
>
> I've created a .ui file through Qt Designer and followed the multiple
> inheritance approach from the "Compile Time Form Processing"
> section of Qt
> Designer's manual. Then I've added a protected slot to the child
> class and
> proceeded to try to connect a signal from a UI component to that
> particular
> slot. The code compiles but when I run the app, I get the following
> output:
>
> <output>
> Object::connect: No such slot QMainWindow::connection()
> Object::connect: (sender name: 'actionConnect')
> Object::connect: (receiver name: 'MainWindowy')
> </output>
>
>
> The code is as follows:
>
> <declaration>
> #include <QMainWindow>
> #include "ui_MainWindow.h"
>
>
> class MainWindow :
> public QMainWindow,
> private Ui::MainWindowy
> {
> // snip
> public:
> MainWindow();
> ~MainWindow();
>
> protected slots:
> void connection();
>
> // snip
> };
> </declaration>
>
>
> <implementation>
> #include "mainwindow.hpp"
>
> MainWindow::MainWindow()
> : QMainWindow( NULL )
> {
> setupUi( this );
>
> // signals and slots
> connect(actionConnect, SIGNAL(triggered(bool)), SLOT
> (connection()));
> }
>
> MainWindow::~MainWindow() {}
>
> void MainWindow::connection()
> {
> }
> </implementation>
You forgot about Q_OBJECT macro inside of your class declaration.
class MainWindow:
public QMainWindow,
private Ui::MainWindow
{
Q_OBJECT
public:
...
};
--
[ signature omitted ]
Message 14 in thread
On 2007/8/26, Rui Maciel wrote:
>
> I'm trying to get the hang out of Qt and right now I've hit a small bump
> in
> the road.
>
> I've created a .ui file through Qt Designer and followed the multiple
> inheritance approach from the "Compile Time Form Processing" section of Qt
> Designer's manual. Then I've added a protected slot to the child class and
> proceeded to try to connect a signal from a UI component to that
> particular
> slot. The code compiles but when I run the app, I get the following
> output:
>
> <output>
> Object::connect: No such slot QMainWindow::connection()
> Object::connect: (sender name: 'actionConnect')
> Object::connect: (receiver name: 'MainWindowy')
> </output>
>
>
> The code is as follows:
>
> <declaration>
> #include <QMainWindow>
> #include "ui_MainWindow.h"
class MainWindow :
> public QMainWindow,
> private Ui::MainWindowy
Here could be an error you have derived from Ui::MainWindowy, should it be
Ui::MainWindow?
{
> // snip
> public:
> MainWindow();
> ~MainWindow();
>
> protected slots:
> void connection();
>
> // snip
> };
> </declaration>
>
>
> <implementation>
> #include "mainwindow.hpp"
>
> MainWindow::MainWindow()
> : QMainWindow( NULL )
> {
> setupUi( this );
>
> // signals and slots
> connect(actionConnect, SIGNAL(triggered(bool)),
> SLOT(connection()));
> }
Is "this" missed?
MainWindow::~MainWindow() {}
>
> void MainWindow::connection()
> {
> }
> </implementation>
>
>
> So,what am I missing? Why is QObject::connect pointing to the QMainWindow
> class instead of the MainWindow class?
>
>
> Thanks in advance
> Rui Maciel
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 15 in thread
Francisco Gonzalez wrote:
> Here could be an error you have derived from Ui::MainWindowy, should it be
> Ui::MainWindow?
That was a remnant of a test I made to see if the problem wasn't due to some
inheritance issue, being the derived class named MainWindow and one of the
base classes named Ui::MainWindow.
I should've corrected that before pasting the example code. Sorry about
that.
But the problem is no more. It was solved by adding Q_OBJECT to the class
and re-building the project with Qt4 tools instead of the Qt3 tools which I
was using at the time, unaware.
Rui Maciel
--
[ signature omitted ]