PDA

View Full Version : QDialog::exec() Segmentation fault



csavarese
20th May 2013, 23:54
Hi all,
I'm new, so please feel free to question me on the obvious stuff, and to recommend any relevant reading. Also, I'll do my best to supply any additional information that might help you help me. Please ask!

I'm seeing a segmentation fault with the following backtrace:



Program received signal SIGSEGV, Segmentation fault.
0x06fcc04f in QWidget::testAttribute_helper(Qt::WidgetAttribute) const ()
from /usr/lib/qt4/lib/libQtGui.so.4
(gdb) backtrace
#0 0x06fcc04f in QWidget::testAttribute_helper(Qt::WidgetAttribute) const ()
from /usr/lib/qt4/lib/libQtGui.so.4
#1 0x06fd433f in QWidget::setAttribute(Qt::WidgetAttribute, bool) () from /usr/lib/qt4/lib/libQtGui.so.4
#2 0x07301008 in QDialog::exec() () from /usr/lib/qt4/lib/libQtGui.so.4


Here's the code in question:


QProgressDialog* m_pProgressDialog;

// Create the progress dialog.
m_pProgressDialog = new QProgressDialog( "Operation in Progress", "&Cancel", 0, 100 );
m_pProgressDialog->setWindowTitle( "Operation in Progress" );
m_pProgressDialog->setFixedSize( 300, 100 );
m_pProgressDialog->setModal( true );

// Connect to the cancel button.
connect( m_pProgressDialog, SIGNAL( canceled() ), SLOT( CancelOperation() ) );

// Show the dialog and continue
m_pProgressDialog->exec();


I've been Googling, reading your forums, debugging, and scratching my head for hours, and I can't figure out what to look for next. If you have any suggestions, I'd really appreciate it.
Thanks!

Qt4, Linux, g++

wysota
21st May 2013, 00:35
Is this your actual code?

csavarese
21st May 2013, 00:38
I inherited it from a previous designer, and the pointer declaration is actually in a different file, but otherwise, yes. It's a snippet of the actual code I'm compiling and running.
Did I already miss something obvious?

wysota
21st May 2013, 00:47
Show us your actual code. Make sure you call exec on the same variable as the one you initialize in line #4 of what you posted. Note that I mean the same variable, not variable with the same name.

csavarese
21st May 2013, 19:11
Hi wysota,
I was in the process of sorting through code to honor your request as best I could. I'm not at liberty to show it all unfortunately. Doing so helped me find the problem! I'm back to say thank you, and to share what I found in case someone else Googles their way here.

There's a warning in the Qt docs to never delete an object in a thread other than the one that created it. Oops. This code juggles a few threads, and sure enough I was guilty of this. I changed "delete obj" to "obj->deleteLater()", and the crashes went away.

Thanks again!