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

Subclassing KMainWindow crashes on exit [SOLVED]

Tags: None
(comma "," separated)
Musikolo
Registered Member
Posts
27
Karma
0
OS
Hi,

I'm trying to do an application based on KDE architecture. I've done a lot of progress on my own, but I have an issue regarding KMainWindow that I haven't been able to find a solution. I would like my MainWindow class subclasses KMainwindow and a Qt Design UI. The problem is that, although the application compiles and works, it crashes when the quit() event is launched. However, If I subclass from QMainWindow instead, the whole application seamlessly, including the quit() event. See this the next code for more details:

Code: Select all
#ifndef MainWindow_H
#define MainWindow_H

#include <QNetworkAccessManager>
#include "ui_mainwindow.h"
#include "httpconnector.h"

// ** Start **: This code crahes
// #include <KMainWindow>
// class MainWindow : public KMainWindow, private Ui::MainWindow
// ** End **

// ** Start ** - This code works seamlessly
#include <QtGui/QMainWindow>
class MainWindow : public QMainWindow, private Ui::MainWindow
// ** End **

{
Q_OBJECT
private:
   QNetworkAccessManager * networkManager;
   HttpConnector * connector;
    const QModelIndex taskTableModel;
private slots:
   void openFile();
   void openUrl();
   void reset();
   void submit();
public:
    MainWindow( );
    virtual ~MainWindow();
};

#endif // MainWindow_H

As you can see, there are two sections, one where MainWindow subclasses KMainWindow that's having the mentioned problem, and the other one subclassing QMainWindow that's working perfectly.

What could I do to sort out this problem? ???

Best regards!

Last edited by Musikolo on Mon Dec 06, 2010 12:09 pm, edited 1 time in total.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Are you using KApplication instead of QApplication in your main()?

Also, do you have a backtrace for this crash?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
pinotree
KDE Developer
Posts
222
Karma
7
OS
In case you are doing that, do not construct in main() the main window object on the stack, but allocate it on the heap (with new), without deleting it yourself.


Pino Toscano
Musikolo
Registered Member
Posts
27
Karma
0
OS
Hi everyone,

@pinotree: You deserve to be the king of the kingdom. I have just replaced, as you suggested, this:
Code: Select all
   MainWindow mainWindow;
   mainWindow.show();

for this other thing:
Code: Select all
   MainWindow * mainWindow = new MainWindow();
   mainWindow->show();

Now it works seamlessly! :)

@bcooksley: I'm using KApplication in my main.

@Everyone: Thanks a million for you unconditional support! ;)
B4700011
Registered Member
Posts
16
Karma
0
@pinotree: You deserve to be the king of the kingdom.


Seconded! :*

I'd spent hours scratching my head about this. Somehow couldn't get Google to come up with any sensible leads.

Thanks much indeed.
pinotree
KDE Developer
Posts
222
Karma
7
OS
Note this is written in the KMainWinow API documentation:
http://api.kde.org/4.5-api/kdelibs-apid ... 3fe46149d0


Pino Toscano
B4700011
Registered Member
Posts
16
Karma
0
pinotree wrote:Note this is written in the KMainWinow API documentation:
http://api.kde.org/4.5-api/kdelibs-apid ... 3fe46149d0


Indeed:
KMainWindows must be created on the heap with 'new', like:

KMainWindow *kmw = new KMainWindow(...);
kmw->setObjectName(...);


Must have read that a hundred times, but it just never registered. :-[
pinotree
KDE Developer
Posts
222
Karma
7
OS
B4700011 wrote:Must have read that a hundred times, but it just never registered. :-[

No problem, it happens some times :)


Pino Toscano


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient