[SOLVED] Qt4 Custom Window not compiling

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

[SOLVED] Qt4 Custom Window not compiling

Post by lotios611 »

I'm trying to make a custom QMainWindow. I have this error:
:20: multiple definition of `non-virtual thunk to MainWindow::~MainWindow()'
:15: multiple definition of `MainWindow::~MainWindow()'
:9: first defined here
Here's the code I'm trying to compile:

MainWindow.h:

Code: Select all

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QFileDialog>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QMainWindow *parent = 0);
    virtual ~MainWindow();

private:
    QMenu *file;
    QAction *save;
    QFileDialog *saveDialog;

private slots:
    void newLevel();
    void saveLevel();
    void loadLevel();
};

#endif // MAINWINDOW_H
Here's MainWindow.cpp:

Code: Select all

#include "MainWindow.h"

MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent)
{
    setWindowIcon(QIcon("icon.png"));
    setWindowTitle("Level Editor Development Version");
    setPalette(QPalette(Qt::white));

    file = menuBar()->addMenu("&File");
    save = new QAction("&Save", this);
    file->addAction(save);
    connect(save, SIGNAL(triggered()), this, SLOT(saveLevel()));
}

MainWindow::~MainWindow()
{
    delete file;
    delete save;
    delete saveDialog;
}

void MainWindow::saveLevel()
{
    saveDialog->getSaveFileName(NULL, "File:");
    saveDialog->show();
}

void MainWindow::loadLevel()
{
}

void MainWindow::newLevel()
{
}
I'm using Qt Creator to develop.
Last edited by lotios611 on Sun Jan 17, 2010 12:47 pm, edited 1 time in total.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
dani93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Mon Apr 13, 2009 9:38 am
Location: Austria

Re: Qt4 Custom Window not compiling

Post by dani93 »

Works fine for me on Ubuntu with Qt 4.5.2. However there are two bugs in it:
1) You don't allocate memory for saveDialog -> Segmentation fault
2) You don't need to call getSaveFileName and show on saveDialog. getSaveFileName alone is enough.
Try recompiling the complete project (also run qmake), this often removes weird errors.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Qt4 Help

Post by lotios611 »

Thanks! I have another question though. I'm trying to open a program from within my program. I've looked into QProcess, but none of the examples I've tried work.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
dani93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Mon Apr 13, 2009 9:38 am
Location: Austria

Re: Qt4 Help

Post by dani93 »

lotios611 wrote:Thanks!
So you solved the problem by just recompiling the project?
lotios611 wrote:I have another question though. I'm trying to open a program from within my program. I've looked into QProcess, but none of the examples I've tried work.
I have never used QProcess, so I can't tell you much about it. Maybe if you show me your code. "system" would be a very ugly but simple solution.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Qt4 Custom Window not compiling

Post by lotios611 »

dani93 wrote:
lotios611 wrote:Thanks!
So you solved the problem by just recompiling the project?
That, and changing the other things you said.
dani93 wrote: I have never used QProcess, so I can't tell you much about it. Maybe if you show me your code. "system" would be a very ugly but simple solution.
Here's some code:

Code: Select all

#include <QtGui>
#include <QProcess>
#include <QStringList>
#include "MainWindow.h"

 int main(int argc, char *argv[])
 {
    QApplication app(argc, argv);
    MainWindow window; //My Custom window
    window.show();
    QProcess process(&window);
    process.start("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    return app.exec();
 }
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
dani93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Mon Apr 13, 2009 9:38 am
Location: Austria

Re: Qt4 Custom Window not compiling

Post by dani93 »

lotios611 wrote:Here's some code:
[...]
Works perfect for me again. Another reason I don't like Windows... the paths. Although you already corrected the backslashes in the path, I'm quite sure that the spaces are making problems. Don't know how you can avoid such things on Windows, but you could try something like that:

Code: Select all

process.start("\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\"");
So Windows will interpret it as one command, not as several separated by spaces (I hope...).

BTW: If you only want to open an URL in the default browser you can use QDesktopServices::openUrl (QUrl); You can never be sure that everyone has installed Firefox (even in the same directory?!). Qt was designed to be platform independent. Something like starting a process with a static path destroys everything.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Qt4 Custom Window not compiling

Post by lotios611 »

Thanks again. I was using firefox to test it out. BTW, how long have you been using Qt? I just started, I think that my project's way too ambitious.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
dani93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Mon Apr 13, 2009 9:38 am
Location: Austria

Re: Qt4 Custom Window not compiling

Post by dani93 »

lotios611 wrote:BTW, how long have you been using Qt? I just started, I think that my project's way too ambitious.
I have been using Qt for about half a year. I think it is incredibly easy to learn.
Post Reply