Results 1 to 20 of 25

Thread: Interesting little Segfault w/r to signal/slot connection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    Did you try to run "make clean && make"? Did you enable warnings during compilation?

    Does this crash?
    Qt Code:
    1. #include <QApplication>
    2.  
    3. int main( int argc, char **argv )
    4. {
    5. QApplication app( argc, argv );
    6. QObject::connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( aboutQt() ) );
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    I've done make clean && make many times

    all warnings are enabled, only one I get it the one about the slot not using one of the parameters, but that's usually a harmless warning.

    That code compiles and runs without incident.

    Attempting to print out the address of the m_munPhRanges table at the point of the crash yields the following, which I've never seen before...
    Qt Code:
    1. (gdb) print DataGen::m_munPhRanges
    2. $1 = (class QTableWidget (* DataGen::&)) DataGen::QMainWindow + 168 bytes
    To copy to clipboard, switch view to plain text mode 
    Last edited by Hydragyrum; 12th September 2006 at 15:47.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    Quote Originally Posted by Hydragyrum
    That code compiles and runs without incident.
    Then most likely there is something in your application that causes the crash, since QObject::connect() itself works.

    Maybe this will shed some light (you will have to add #include <QtDebug>):
    Qt Code:
    1. void DataGen::setUpConnections()
    2. {
    3. qDebug() << m_munPhRanges->rowCount() << m_munPkRanges->rowCount();
    4. qDebug() << this->metaObject()->className();
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 
    Does it crash on qDebug()?

  4. #4
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    I have a feeling it's not initializing the tables at all...but it's wierd.

    The backtrace clearly shows it entering the setUpConnections function from line 45. but if I set a breakpoint at say line 39, which is still inside my constructor, the breakpoint is never reached...

    here's the steps I did in gdb and the output:

    (gdb) info break
    Num Type Disp Enb Address What
    1 breakpoint keep y 0x0804d1a1 in DataGen at datagen.cpp:39
    (gdb) run
    The program being debugged has been started already.
    Start it from the beginning? (y or n) y
    Starting program: /home/abertrand/test/datagen/datagen_debug
    Error while mapping shared library sections:
    : Success.
    Error while reading shared library symbols:
    : No such file or directory.
    [Thread debugging using libthread_db enabled]
    [New Thread -150503296 (LWP 9579)]
    Error while reading shared library symbols:
    : No such file or directory.
    Error while reading shared library symbols:
    : No such file or directory.
    Qt: gdb: -nograb added to command-line options.
    Use the -dograb option to enforce grabbing.
    Error while reading shared library symbols:
    : No such file or directory.
    Error while reading shared library symbols:
    : No such file or directory.
    Error while reading shared library symbols:
    : No such file or directory.
    Error while reading shared library symbols:
    : No such file or directory.
    Error while reading shared library symbols:
    : No such file or directory.
    Error while reading shared library symbols:
    : No such file or directory.

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -150503296 (LWP 9579)]
    0x00427c67 in QObject::connect (sender=0x885cea0, signal=0x805c670 "2currentItemChanged( QTableWidgetItem *, QTableWidgetItem * )", receiver=0x87ee688,
    method=0x805c63c "1validate( QTableWidgetItem *, QTableWidgetItem * )", type=AutoConnection) at kernel/qobject.cpp:2134
    2134 kernel/qobject.cpp: No such file or directory.
    in kernel/qobject.cpp
    (gdb) bt
    #0 0x00427c67 in QObject::connect (sender=0x885cea0, signal=0x805c670 "2currentItemChanged( QTableWidgetItem *, QTableWidgetItem * )", receiver=0x87ee688,
    method=0x805c63c "1validate( QTableWidgetItem *, QTableWidgetItem * )", type=AutoConnection) at kernel/qobject.cpp:2134
    #1 0x080563d8 in DataGen::setUpConnections (this=0x87ee688) at datagen.cpp:553
    #2 0x0804d4b4 in DataGen (this=0x87ee688) at datagen.cpp:45
    #3 0x08057da7 in main (argc=1, argv=0xfeef1054) at main.cpp:13
    A similar breakpoint set at line 45 in datagen.cpp is also not being hit, even though the backtrace claims to reach it.

    The question is now how is the function being called, if it's never being called?

    here's the output of our little experiment, along with a backtrace:

    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. [Switching to Thread -150552448 (LWP 9661)]
    3. 0x0069de2c in QTableWidgetPrivate::q_func (this=0x0) at itemviews/qtablewidget.cpp:1239
    4. 1239 itemviews/qtablewidget.cpp: No such file or directory.
    5. in itemviews/qtablewidget.cpp
    6. (gdb) bt
    7. #0 0x0069de2c in QTableWidgetPrivate::q_func (this=0x0) at itemviews/qtablewidget.cpp:1239
    8. #1 0x0069d39c in QTableWidgetPrivate::model (this=0x0) at itemviews/qtablewidget.cpp:1242
    9. #2 0x00699034 in QTableWidget::rowCount (this=0x88db890) at itemviews/qtablewidget.cpp:1538
    10. #3 0x08056859 in DataGen::setUpConnections (this=0x8868688) at datagen.cpp:553
    11. #4 0x0804d940 in DataGen (this=0x8868688) at datagen.cpp:46
    12. #5 0x08058643 in main (argc=1, argv=0xfeefbb64) at main.cpp:13
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 12th September 2006 at 16:14. Reason: changed [ code ] to [ quote ] to allow wrapping

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    Quote Originally Posted by Hydragyrum
    1 breakpoint keep y 0x0804d1a1 in DataGen at datagen.cpp:39
    #2 0x0804d4b4 in DataGen (this=0x87ee688) at datagen.cpp:45
    These two addresses are a bit too far away for me.

    Quote Originally Posted by Hydragyrum
    #0 0x0069de2c in QTableWidgetPrivate::q_func (this=0x0) at itemviews/qtablewidget.cpp:1239
    This clearly shows that QTableWidget wasn't initialized properly or something has happened to it. Maybe it was overwritten? In that case valgrind might help.

    Another test:
    Qt Code:
    1. #include <QApplication>
    2. #include <QTableWidget>
    3.  
    4. int main( int argc, char **argv )
    5. {
    6. QApplication app( argc, argv );
    7.  
    8. QTableWidget *m_munPhRanges = new QTableWidget();
    9. m_munPhRanges->setRowCount( 3 );
    10. m_munPhRanges->setColumnCount( 5 );
    11. m_munPhRanges->setFixedSize( 635, 110 );
    12. m_munPhRanges->setRowHeight( 0, 20 );
    13. m_munPhRanges->setRowHeight( 1, 20 );
    14. m_munPhRanges->setRowHeight( 2, 20 );
    15.  
    16. QObject::connect( m_munPhRanges, SIGNAL( cellClicked( int, int ) ),
    17. &app, SLOT( aboutQt() ) );
    18.  
    19. m_munPhRanges->show();
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    the addresses just pointed out something interesting, possibly with GDB being broken on this machine...

    1 breakpoint keep y 0x0804d6a9 in DataGen at datagen.cpp:46
    #4 0x0804d940 in DataGen (this=0x90d4688) at datagen.cpp:46

    ...these should be the same, no?

    the above code works.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    Quote Originally Posted by Hydragyrum
    ...these should be the same, no?
    IMO they should, but I don't use gdb a lot. Maybe this address changes when you restart your application? Or maybe grsecurity/PAX/whatever messes those addresses?

    Quote Originally Posted by Hydragyrum
    the above code works.
    What happens when you put those qDebug() statements at the end of setUpWidgets()? If it crashes, try to move them somewhere around the middle of that method. If it still crashes move it up, if not --- down. Maybe this way you will locate the source of the problem.

  8. The following user says thank you to jacek for this useful post:

    Hydragyrum (12th September 2006)

  9. #8
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    just tried the build on the windows box to see if it was a machine dependent thing, GDB shows a similar offset between the actual breakpoint, and where it says the function is in the stack...

    It also crashes at exactly the same point in Windows as well...

  10. #9
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    put the qDebug statements right after the functions were initialized.

    3 2
    DataGen
    was the output. which leads me to beleive that the tables are initialized.

    although if I drop them down, things go boom. alright, I think we're close to a solution. Which I got sidetracked by gdb being screwy.

    Edit: ok, found the problem, and well, it was a pretty stupid PEBCAK error. I had added the table to a layout, which was added to a widget, which was added to a scrollarea, which was added to a stacked widget. I had another layout tacked on to another widget and another scroll area to tack onto the stackedwidget, but I typoed the name of that second scrollarea when I added the widget, and wrote in the name of the first instead, thus things got overwritten or exploded when I tried to add the second widget on top of the first.

    Only such screwups are virtually indetectable when there are a few hundred lines to set up the layout and stuff.

    Thanks for the help. I figured it was a stupid mistake somewhere, but didn't realize how stupid. GDB didn't help me much.
    Last edited by Hydragyrum; 12th September 2006 at 17:16. Reason: Problem solved...

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    Quote Originally Posted by Hydragyrum
    but I typoed the name of that second scrollarea when I added the widget, and wrote in the name of the first instead, thus things got overwritten or exploded when I tried to add the second widget on top of the first.
    The only explanation is that Qt has deleted something, when you set the layout again.

    Quote Originally Posted by Hydragyrum
    Only such screwups are virtually indetectable when there are a few hundred lines to set up the layout and stuff.
    Well... Qt Designer doesn't do such mistakes.

  12. #11
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    heh, but I find Qt Designer a little difficult to work with...

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    Quote Originally Posted by Hydragyrum
    I find Qt Designer a little difficult to work with...
    Everyone has it's own way of doing things, but maybe it's just matter of getting used to it? IMO Designer, not only helps to avoid bugs, but also you can make changes in the GUI easier. The way that uic works in Qt4 is much more flexible than it was in Qt3.

  14. #13
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Interesting little Segfault w/r to signal/slot connection

    possibly, the designer has a few quirks of it's own though. Maybe I'll try using it again in my next project.

Similar Threads

  1. Interesting tutorial on UI Designer
    By GreyGeek in forum Qt Tools
    Replies: 1
    Last Post: 6th August 2006, 08:43
  2. segfault
    By conexion2000 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2006, 12:34
  3. Why does setTextColor() cause a segfault?
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 16:58
  4. Replies: 10
    Last Post: 10th February 2006, 00:15
  5. use interesting QWT Library with QT3.X
    By raphaelf in forum Qwt
    Replies: 2
    Last Post: 23rd January 2006, 11:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.