Qt-interest Archive, April 2008
QCheckBox in a QPopupMenu: segmentation fault
Message 1 in thread
Hello,
I am running qt 3.3.7 on Linux Debian.
I'm using a QLineEdit with a context menu (created by reimplementing
createPopupMenu). This menu has a submenu and a QCheckBox. It works fine
except that it sometimes segfaults.
In the example below, when the cursor goes slowly from the second item
of the submenu to the checkbox, it crashes.
The backtrace shows a huge number of frames (34686) and it seems that qt
make an infinite loop (QPopupMenu::mouseMoveEvent,
QApplication::sendEvent,
QApplication::notify,QApplication::internalNotify, QWidget::event,
QPopupMenu::mouseMoveEvent, ....).
Any clues to solve the problem?
Thanks in advance.
Example:
#include <qapplication.h>
#include <qlineedit.h>
#include <qstring.h>
#include <stdio.h>
#include <qpopupmenu.h>
#include <qcheckbox.h>
class MyQLineEdit:public QLineEdit{
public:
MyQLineEdit(QWidget* parent=0, const char *name=0):
QLineEdit(parent, name){}
protected:
QPopupMenu* createPopupMenu(){
QPopupMenu* menu = new QPopupMenu(this);
QPopupMenu* sousmenu = new QPopupMenu(menu);
sousmenu->insertItem("Item1");
sousmenu->insertItem("Item2");
menu->insertItem("sous-menu", sousmenu);
QCheckBox* cb = new QCheckBox(QString("Enabled"), menu);
menu->insertItem(cb);
return menu;
}
};
int main(int argc, char** argv){
QApplication qapp(argc, argv);
QLineEdit* ql = new MyQLineEdit();
qapp.setMainWidget(ql);
ql->show();
return qapp.exec();
}
--
[ signature omitted ]
Message 2 in thread
Romain Jacquet wrote:
> Hello,
>
>
> I am running qt 3.3.7 on Linux Debian.
> I'm using a QLineEdit with a context menu (created by reimplementing
> createPopupMenu). This menu has a submenu and a QCheckBox. It works
> fine except that it sometimes segfaults.
Maybe I don't get what you want to achieve there, but I wonder why you
use a QCheckBox at all. Why don't you use setCheckable(),
setItemChecked( int id, bool check ) and isItemChecked( int id )
instead? Then toggle the checked status of the "Enabled" item every time
you select the item...
HTH, Hel
>
> In the example below, when the cursor goes slowly from the second item
> of the submenu to the checkbox, it crashes.
>
> The backtrace shows a huge number of frames (34686) and it seems that
> qt make an infinite loop (QPopupMenu::mouseMoveEvent,
> QApplication::sendEvent,
> QApplication::notify,QApplication::internalNotify, QWidget::event,
> QPopupMenu::mouseMoveEvent, ....).
>
> Any clues to solve the problem?
> Thanks in advance.
>
>
>
>
>
> Example:
>
> #include <qapplication.h>
> #include <qlineedit.h>
> #include <qstring.h>
> #include <stdio.h>
> #include <qpopupmenu.h>
> #include <qcheckbox.h>
>
>
> class MyQLineEdit:public QLineEdit{
> public:
> MyQLineEdit(QWidget* parent=0, const char *name=0):
> QLineEdit(parent, name){}
>
>
> protected:
> QPopupMenu* createPopupMenu(){
> QPopupMenu* menu = new QPopupMenu(this);
> QPopupMenu* sousmenu = new QPopupMenu(menu);
> sousmenu->insertItem("Item1");
> sousmenu->insertItem("Item2");
> menu->insertItem("sous-menu", sousmenu);
> QCheckBox* cb = new QCheckBox(QString("Enabled"), menu);
> menu->insertItem(cb);
> return menu;
> }
> };
>
>
> int main(int argc, char** argv){
> QApplication qapp(argc, argv);
> QLineEdit* ql = new MyQLineEdit();
> qapp.setMainWidget(ql);
> ql->show();
> return qapp.exec();
> }
>
>
> --
> 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/
>
--
[ signature omitted ]
Message 3 in thread
Helge Preuss a écrit :
> Maybe I don't get what you want to achieve there, but I wonder why you
> use a QCheckBox at all. Why don't you use setCheckable(),
> setItemChecked( int id, bool check ) and isItemChecked( int id )
> instead? Then toggle the checked status of the "Enabled" item every
> time you select the item...
>
>
> HTH, Hel
This context menu have both checkables item and non-checkables items. By
using the functionn setCheckable() all items become checkable or
non-checkable.
--
[ signature omitted ]
Message 4 in thread
Romain Jacquet wrote:
> Helge Preuss a écrit :
>> Maybe I don't get what you want to achieve there, but I wonder why
>> you use a QCheckBox at all. Why don't you use setCheckable(),
>> setItemChecked( int id, bool check ) and isItemChecked( int id )
>> instead? Then toggle the checked status of the "Enabled" item every
>> time you select the item...
>>
>>
>> HTH, Hel
>
> This context menu have both checkables item and non-checkables items.
> By using the functionn setCheckable() all items become checkable or
> non-checkable.
In that case, I can only recommend upgrading to Qt4. In Qt4 you can
setCheckable() per item instead of per menu.
I have had the situation described in a Qt3 application, but I have
upgraded it to Qt4 since and I don't remember how I dealt with the
problem in the Qt3 version - I guess I just lived with it.
Greets, Hel
--
[ signature omitted ]