[Qt-interest] program crashes when right mouse button clicked on the gui

Reece Dunn msclrhd at googlemail.com
Wed Jun 2 10:02:24 CEST 2010


2010/6/2 hakiim the dream <hakiim35 at hotmail.com>:
> Hi, I am developing a desktop application which is an image
> processing/editing app similar to the GIMP or PaintDotNet.
> The problem is, whenever I click the right mouse button on the gui, the
> program enters into the "qscopedpointer.h" and
> throws an exception on the "inline T *data() const" function.
> I can't even debug the problem since it crashes whereever you right-click on
> the gui.

You can debug the program. What compiler/development platform are you using?

If you are using gcc, you can use gdb to help debug the application
(or possibly some other debuggers as well). I am not familiar enough
with gdb to help you out. Google may help here.

If you are using Visual Studio, simply:
  1/  be sure to turn on trapping for all exceptions in the Debug >
Exceptions menu (including the check box for break on throw);
  2/  run the application from Visual Studio in debug mode;
  3/  press the right mouse button on the application (or whatever
will trigger the crash)

You will now be able to analyse the crash.
  a/  If you look at the call stack (one of the Debug > Window items),
you can navigate back through the call chain to see where the error is
occurring;
  b/  If you hover over a variable in the source window, you can see
the value of that variable.

> The gui contains distinct widgets such as QGraphicsView, QListWidget,
> QPushButton, etc.
> Should I implement a right-click handler for each of the widgets? It doesn't
> make sense to me..
> What would you suggest?

It seems to me like you have a context menu that is invalid -- context
menus get invoked on right-click by Qt.

Do you have a contextMenuEvent handler? If so, does it look something like this:

class MyEditor : public QTextEdit
{
public:

   MyEditor()
   {
      m_menu = new QMenu(this);
   }

   void contextMenuEvent(QContextMenuEvent *event)
   {
      m_menu->exec(event->globalPos());
   }

private:

   QMenu * m_menu;
};

- Reece




More information about the Qt-interest-old mailing list