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

Treeview in Plasmoid Configuration Dialog crashes.

Tags: None
(comma "," separated)
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
I am trying to add a tree view to my configuration dialog but trying to add a model to it crashes the plasmoid.

http://doc.qt.nokia.com/4.6/itemviews-s ... model.html

I am using that as a reference... pretty much after failing with my own implementation I'm trying to get their one working first before making changes...

I have:

Code: Select all
void KDrawer::createConfigurationInterface(KConfigDialog *parent) {
  //connect(parent, SIGNAL(applyClicked()),   this, SLOT(configAccepted()));
  //connect(parent, SIGNAL(okClicked()),      this, SLOT(configAccepted()));
  //connect(parent, SIGNAL(defaultClicked()), this, SLOT(loadDefaults()));

  parent->showButton(KConfigDialog::Help, false);
  parent->enableButton(KConfigDialog::Default, true);
 
  QFile file("/home/beaverusiv/code/KDrawer/default.txt");
  file.open(QIODevice::ReadOnly);
  TreeModel model(file.readAll());
  file.close();
 
  //TreeModel model(config);

  QWidget *widgetM = new QWidget;
  m_settingsMenu.m_menuTree->setModel(&model);
  m_settingsMenu.setupUi(widgetM);
  parent->addPage(widgetM, i18n("Menu"), icon());
  parent->setInitialSize(QSize(660, 351));
}


default.txt:
Code: Select all
 Getting Started                         How to familiarize yourself with Qt Designer
     Launching Designer                  Running the Qt Designer application
     The User Interface                  How to interact with Qt Designer
 Connection Editing Mode                 Connecting widgets together with signals and slots
     Connecting Objects                  Making connections in Qt Designer
     Editing Connections                 Changing existing connections


Any help is greatly appreciated.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Have you tried using gdb to trace where the crash occurs?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
Sorry, I'm new to KDE/Linux programming; how do I debug the plasmoid? (It isn't an executable itself is it?)
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You can use the following procedure to debug the Plasmoid. First start gdb.
Code: Select all
gdb plasmoidviewer


Then, start Plasmoidviewer, loading your plasmoid. Type at the gdb prompt:
Code: Select all
run name_of_your_plasmoid_goes_here


When it crashes, the gdb prompt should be returned to you. Enter "bt" to generate a backtrace, and post that here.

Then enter "quit" to close gdb, and plasmoidviewer.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
Thanks, I couldn't find how to do it on the Internet.

Code: Select all
(gdb) run kdrawer
Starting program: /usr/bin/plasmoidviewer kdrawer
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0xa7cc0ee4 in KDrawer::createConfigurationInterface (this=0x814d810,
    parent=0x8391df8) at /home/beaverusiv/code/KDrawer/kdrawer.cpp:126
126       m_settingsMenu.m_menuTree->setModel(&model);
(gdb) bt
#0  0xa7cc0ee4 in KDrawer::createConfigurationInterface (this=0x814d810,
    parent=0x8391df8) at /home/beaverusiv/code/KDrawer/kdrawer.cpp:126
#1  0xb7a8d88e in Plasma::AppletPrivate::generateGenericConfigDialog() ()
   from /usr/lib/libplasma.so.3
#2  0xb7a91b18 in Plasma::Applet::showConfigurationInterface() ()
   from /usr/lib/libplasma.so.3
#3  0xb7a9ce63 in Plasma::Applet::qt_metacall(QMetaObject::Call, int, void**) ()   
   from /usr/lib/libplasma.so.3                                                   
#4  0xa7cc08e2 in KDrawer::qt_metacall (this=0x814d810,                           
    _c=QMetaObject::InvokeMetaMethod, _id=28, _a=0xbfffcb38)                       
    at /home/beaverusiv/code/KDrawer/build/kdrawer.moc:66
#5  0xb7698eba in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**)
    () from /usr/lib/libQtCore.so.4
#6  0xb76a7f9b in QMetaObject::activate(QObject*, QMetaObject const*, int, void**)
    () from /usr/lib/libQtCore.so.4
#7  0xb6c14c99 in QAction::triggered(bool) () from /usr/lib/libQtGui.so.4
#8  0xb6c14efb in QAction::activate(QAction::ActionEvent) ()
   from /usr/lib/libQtGui.so.4
#9  0xb7095b2d in ?? () from /usr/lib/libQtGui.so.4
#10 0xb709c633 in ?? () from /usr/lib/libQtGui.so.4
#11 0xb709d9df in QMenu::mouseReleaseEvent(QMouseEvent*) ()
   from /usr/lib/libQtGui.so.4
#12 0xb7eeb414 in KMenu::mouseReleaseEvent(QMouseEvent*) ()
   from /usr/lib/libkdeui.so.5
#13 0xb6c7312a in QWidget::event(QEvent*) () from /usr/lib/libQtGui.so.4
#14 0xb709da5c in QMenu::event(QEvent*) () from /usr/lib/libQtGui.so.4
#15 0xb6c1bf14 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/libQtGui.so.4
#16 0xb6c20ab9 in QApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/libQtGui.so.4
#17 0xb7e063ea in KApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/libkdeui.so.5
#18 0xb7692ecb in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
   from /usr/lib/libQtCore.so.4
#19 0xb6c1cdc7 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () from /usr/lib/libQtGui.so.4
#20 0xb6ca1ff4 in ?? () from /usr/lib/libQtGui.so.4
#21 0xb6ca0f69 in QApplication::x11ProcessEvent(_XEvent*) ()
   from /usr/lib/libQtGui.so.4
#22 0xb6cc8572 in ?? () from /usr/lib/libQtGui.so.4
#23 0xb4d64f72 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#24 0xb4d65750 in g_main_context_iterate () from /usr/lib/libglib-2.0.so.0
#25 0xb4d65a04 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
---Type <return> to continue, or q <return> to quit---
#26 0xb76bde7c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#27 0xb6cc81b5 in ?? () from /usr/lib/libQtGui.so.4
#28 0xb7692119 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
    () from /usr/lib/libQtCore.so.4
#29 0xb769238a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/libQtCore.so.4
#30 0xb70999c4 in QMenu::exec(QPoint const&, QAction*) ()
   from /usr/lib/libQtGui.so.4
#31 0xb7aad347 in Plasma::ContainmentPrivate::showContextMenu(QPointF const&, QPoint const&, bool, bool) () from /usr/lib/libplasma.so.3
#32 0xb7aad46a in Plasma::Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent*) () from /usr/lib/libplasma.so.3
#33 0xb724ae8e in QGraphicsItem::sceneEvent(QEvent*) ()
   from /usr/lib/libQtGui.so.4
#34 0xb729f457 in QGraphicsWidget::sceneEvent(QEvent*) ()
   from /usr/lib/libQtGui.so.4
#35 0xb726d930 in ?? () from /usr/lib/libQtGui.so.4
#36 0xb726e088 in QGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent*) () from /usr/lib/libQtGui.so.4
#37 0xb7281a0c in QGraphicsScene::event(QEvent*) () from /usr/lib/libQtGui.so.4
#38 0xb6c1bf14 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/libQtGui.so.4
#39 0xb6c200fe in QApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/libQtGui.so.4
#40 0xb7e063ea in KApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/libkdeui.so.5
#41 0xb7692ecb in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
   from /usr/lib/libQtCore.so.4
#42 0xb7294ab4 in QGraphicsView::contextMenuEvent(QContextMenuEvent*) ()
   from /usr/lib/libQtGui.so.4
#43 0xb6c73cd8 in QWidget::event(QEvent*) () from /usr/lib/libQtGui.so.4
#44 0xb7055cf3 in QFrame::event(QEvent*) () from /usr/lib/libQtGui.so.4
#45 0xb70e2022 in QAbstractScrollArea::viewportEvent(QEvent*) ()
   from /usr/lib/libQtGui.so.4
#46 0xb729dca7 in QGraphicsView::viewportEvent(QEvent*) ()
   from /usr/lib/libQtGui.so.4
#47 0xb70e49c5 in ?? () from /usr/lib/libQtGui.so.4
#48 0xb769306a in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib/libQtCore.so.4
#49 0xb6c1bef0 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/libQtGui.so.4
#50 0xb6c204c3 in QApplication::notify(QObject*, QEvent*) ()
---Type <return> to continue, or q <return> to quit---
   from /usr/lib/libQtGui.so.4
#51 0xb7e063ea in KApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/libkdeui.so.5
#52 0xb7692ecb in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
   from /usr/lib/libQtCore.so.4
#53 0xb6ca1e9d in ?? () from /usr/lib/libQtGui.so.4
#54 0xb6ca0f69 in QApplication::x11ProcessEvent(_XEvent*) ()
   from /usr/lib/libQtGui.so.4
#55 0xb6cc8572 in ?? () from /usr/lib/libQtGui.so.4
#56 0xb4d64f72 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#57 0xb4d65750 in g_main_context_iterate () from /usr/lib/libglib-2.0.so.0
#58 0xb4d65a04 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#59 0xb76bde7c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#60 0xb6cc81b5 in ?? () from /usr/lib/libQtGui.so.4
#61 0xb7692119 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
    () from /usr/lib/libQtCore.so.4
#62 0xb769238a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/libQtCore.so.4
#63 0xb7696c6f in QCoreApplication::exec() () from /usr/lib/libQtCore.so.4
#64 0xb6c19637 in QApplication::exec() () from /usr/lib/libQtGui.so.4
#65 0x080508dd in _start ()
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Try creating your model as follows:

Code: Select all
TreeModel * model = new TreeModel(file.readAll());


And change
Code: Select all
m_settingsMenu.m_menuTree->setModel(&model);

To
Code: Select all
m_settingsMenu.m_menuTree->setModel(model);


Which should fix it. The problem is that the Model is being deleted immediately before the setModel call is made, hence causing it to crash. It is being deleted by compiler automatic garbage cleanup because it is created local to this function, and is no longer used after this function.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
I did that but it still Seg Faults, but calling a function from model is fine, i.e.:

Code: Select all
TreeModel *model = new TreeModel(file.readAll());
...
QModelIndex x = model->index(0, 0);


I also tried making model a member but same Seg Fault, just gdb can't pin down where it happens then.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Is m_settingsMenu created automatically from a *.ui file?
If so, you need to create it first.

Code: Select all
m_settingsMenu.setupUi( <parent of widgets, usually the page you are adding to KConfigDialog> )


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
Ah, ok. Yes it is.

Changed it but it still Seg Faults... :/

Code: Select all
  QFile file("/home/beaverusiv/code/KDrawer/default.txt");
  file.open(QIODevice::ReadOnly);
  TreeModel *model = new TreeModel(file.readAll());
  file.close();
 
  //TreeModel model(config);

  QWidget *widgetM = new QWidget;
  //QModelIndex x = model->index(0, 0);
  m_settingsMenu.setupUi(widgetM);
  //**Tried putting setModel() here too.**
  parent->addPage(widgetM, i18n("Menu"), icon());
  parent->setInitialSize(QSize(660, 351));
  m_settingsMenu.m_menuTree->setModel(model);
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Can you please send me the full sources so I can try to debug it? You can find my address on my profile page.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Thanks. Don't know why the profile page refuses to show my email address.. i'll have to investigate that.

In any case, please find the fixed sources attached to this post.
The issue was caused by the Model incorrectly checking that the parent was valid. I also fixed CMakeLists.txt to generate the *.ui file header automatically.

KDrawer.tar.gz


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
beaverusiv
Registered Member
Posts
13
Karma
0
OS
Thanks very much. It's weird going from .NET/C#/Java programming to KDE/Qt and having very little tutorials and the like to reference.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]