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
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    Good Afternoon

    I've got an interesting little segfault that I can't seem to figure out why it's happening.

    This is using Qt 4.1.0 I beleive.

    First of all, here's a dump of the backtrace:

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -150056832 (LWP 3712)]
    0x00f14c67 in QObject::connect (sender=0x8461ea0, signal=0x805c630 "2currentItemChanged( QTableWidgetItem *, QTableWidgetItem * )", receiver=0x83f3688,
    method=0x805c5fc "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 0x00f14c67 in QObject::connect (sender=0x8461ea0, signal=0x805c630 "2currentItemChanged( QTableWidgetItem *, QTableWidgetItem * )", receiver=0x83f3688,
    method=0x805c5fc "1validate( QTableWidgetItem *, QTableWidgetItem * )", type=AutoConnection) at kernel/qobject.cpp:2134
    #1 0x080563a4 in DataGen::setUpConnections (this=0x83f3688) at datagen.cpp:553
    #2 0x0804d480 in DataGen (this=0x83f3688) at datagen.cpp:45
    #3 0x08057d73 in main (argc=1, argv=0xfef1b434) at main.cpp:12
    At first glance, it seems that the signal slot connection is having a hard time being made. The file not found error seems to point to something wrong with the Qt install, but here's the kicker, the exact same code runs perfectly fine in another project I have, on the same machine no less. So I'm not sure that the Qt install is the problem.

    The code that seems to be closest to causing this fault is in the setUpConnections function, relevent snippet is here:
    Qt Code:
    1. void DataGen::setUpConnections()
    2. {
    3. //Signals and Slot Connections.
    4. //This line is causing the problem, although it's syntactically and semantically correct...at least it seems to be.
    5. connect( m_munPhRanges, SIGNAL( currentItemChanged( QTableWidgetItem *, QTableWidgetItem * ) ),
    6. this, SLOT( validate( QTableWidgetItem *, QTableWidgetItem * ) ) );
    7. connect( m_munPkRanges, SIGNAL( currentItemChanged( QTableWidgetItem *, QTableWidgetItem * ) ),
    8. this, SLOT( validate( QTableWidgetItem *, QTableWidgetItem * ) ) );
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 

    The validate function prototype is as follows:
    Qt Code:
    1. /**
    2.  * @brief Slot used to validate the entries in a table. Called when a cell is finished editing,
    3.  * will turn the cell background red in the event of an invalid input. Values inported from file are assumed to be correct.
    4.  * @param current Pointer to the TableWidgetItem in the current cell (not used, required by the signal).
    5.  * @param previous Pointer to the previously edited TableWidgetItem.
    6.  */
    7. void validate( QTableWidgetItem * current, QTableWidgetItem * previous );
    To copy to clipboard, switch view to plain text mode 

    If there's anything else you guys need, I'll try to see what I can do.

    Thanks.
    Last edited by jacek; 11th September 2006 at 21:30. Reason: reformatted to look better

  2. #2
    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

    Are m_munPhRanges and m_munPkRanges initialized? Can you post the code that does this?

  3. #3
    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

    yeah they are

    Qt Code:
    1. //Set up tables
    2. m_munPhRanges = new QTableWidget();
    3. m_munPhRanges -> setRowCount( 3 );
    4. m_munPhRanges -> setColumnCount( m_numRangesPh );
    5. m_munPhRanges -> setHorizontalHeaderLabels( rgePhHeadH );
    6. m_munPhRanges -> setVerticalHeaderLabels( rgePhHeadV );
    7. m_munPhRanges -> setFixedSize( 635, 110 );
    8. m_munPhRanges -> setRowHeight( 0, 20 );
    9. m_munPhRanges -> setRowHeight( 1, 20 );
    10. m_munPhRanges -> setRowHeight( 2, 20 );
    11.  
    12. m_munPkRanges = new QTableWidget();
    13. m_munPkRanges -> setRowCount( 2 );
    14. m_munPkRanges -> setColumnCount( m_numRangesPk );
    15. m_munPkRanges -> setHorizontalHeaderLabels( rgePkHeadH );
    16. m_munPkRanges -> setVerticalHeaderLabels( rgePkHeadV );
    17. m_munPkRanges -> setFixedSize( 640, 90 );
    18. m_munPkRanges -> setRowHeight( 0, 20 );
    19. m_munPkRanges -> setRowHeight( 1, 20 );
    To copy to clipboard, switch view to plain text mode 

    Everything compiles correctly. The things are also in the class definition in the header.

    As mentioned earlier, I have the exact same setup in a different project (basically rewriting this one to do the same thing, only better) and that one works fine.

  4. #4
    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

    Where is this code placed? Are you sure that it's executed before setUpConnections()?

  5. #5
    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

    yeah, that code is in the setUpWidgets function, which due to it's length, I will not post here. I will post the constructor though...

    Qt Code:
    1. DataGen::DataGen()
    2. {
    3. //We'll set a default value for number of munition ranges to 5. doesn't matter really.
    4. m_numRangesPh = m_numRangesPk = 5;
    5.  
    6. //Set up the widgets.
    7. setUpWidgets();
    8.  
    9. m_dataFile = "";
    10. m_dataDir = QCoreApplication::applicationDirPath ();
    11.  
    12. //Set up the signal/slot connections.
    13. setUpConnections();
    14.  
    15. //Let the selector equal nothing;
    16. m_selector -> setCurrentIndex(-1);
    17.  
    18. //Let the Munition type be nothing by default
    19. m_munType -> setCurrentIndex(-1);
    20.  
    21. //Initialize tables.
    22. initTgtTables();
    23. initMunTables();
    24.  
    25. setWindowFlags ( Qt::WindowMinMaxButtonsHint );
    26. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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

    Does setUpWidgets() happen to be a virtual method?

  7. #7
    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

    Quote Originally Posted by jacek
    Does setUpWidgets() happen to be a virtual method?
    Nope, it's not virtual.

    To me, it doesn't quite look like a code problem, nor an install issue, since it works on another project...I really don't know what else it could be...

  8. #8
    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

    Add:
    Qt Code:
    1. DataGen::DataGen() : m_munPhRanges( 0xdeadbeef ), m_munPkRanges( 0xcafebabe )
    2. {
    3. ...
    To copy to clipboard, switch view to plain text mode 
    and check the stack trace (just to make sure that these variables are initialized).

    Do you create QApplication instance at the beginning of main()? Also check with ldd which Qt library your program is linked with.

  9. #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

    ldd is reporting that everything should be fine, here's the dump

    Qt Code:
    1. linux-gate.so.1 => (0x00c87000)
    2. libQtGui_debug.so.4 => /usr/local/Trolltech/Qt-4.1.0/lib/libQtGui_debug.so.4 (0x00111000)
    3. libpng12.so.0 => /usr/lib/libpng12.so.0 (0x07afc000)
    4. libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x00de0000)
    5. libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x00d48000)
    6. libXi.so.6 => /usr/X11R6/lib/libXi.so.6 (0x0080e000)
    7. libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x00816000)
    8. libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x0081e000)
    9. libXcursor.so.1 => /usr/X11R6/lib/libXcursor.so.1 (0x00821000)
    10. libXinerama.so.1 => /usr/X11R6/lib/libXinerama.so.1 (0x07888000)
    11. libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x0082a000)
    12. libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x0088f000)
    13. libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x00d25000)
    14. libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x008b6000)
    15. libQtCore_debug.so.4 => /usr/local/Trolltech/Qt-4.1.0/lib/libQtCore_debug.so.4 (0x00de8000)
    16. libz.so.1 => /usr/lib/libz.so.1 (0x00d35000)
    17. libdl.so.2 => /lib/libdl.so.2 (0x00c55000)
    18. libpthread.so.0 => /lib/tls/libpthread.so.0 (0x0097e000)
    19. libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x07728000)
    20. libm.so.6 => /lib/tls/libm.so.6 (0x00c30000)
    21. libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00a5a000)
    22. libc.so.6 => /lib/tls/libc.so.6 (0x00b13000)
    23. libexpat.so.0 => /usr/lib/libexpat.so.0 (0x00990000)
    24. /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00afa000)
    To copy to clipboard, switch view to plain text mode 

    I know that these locations all exist.

    As for the initialization thing it's throwing out compile errors about an invalid conversion

    Qt Code:
    1. datagen.cpp: In constructor `DataGen::DataGen()':
    2. datagen.cpp:34: error: invalid conversion from `unsigned int' to `QTableWidget*
    3. '
    4. datagen.cpp:34: error: invalid conversion from `unsigned int' to `QTableWidget*
    5. '
    To copy to clipboard, switch view to plain text mode 

    Trying to solve that problem right now.

    Edit: The QTableWidget pointer doesn't seem to want to let me initialize it's address to a random memory location...
    Last edited by Hydragyrum; 12th September 2006 at 14:46. Reason: update/typo fix

  10. #10
    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

    Another interesting development, my constructor isn't even called...I set a breakpoint at the start of my constructor, and I get the same error, ie the segfault.

    although at least main is being called

    the segfault occurs when trying to initialize my primary class.

    GDB dump follows:

    12 DataGen * d = new DataGen();
    (gdb)
    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.
    0x00f14c67 in QObject::connect (sender=0x816cea0, signal=0x805c630 "2currentItemChanged( QTableWidgetItem *, QTableWidgetItem * )", receiver=0x80fe688,
    method=0x805c5fc "1validate( QTableWidgetItem *, QTableWidgetItem * )", type=AutoConnection) at kernel/qobject.cpp:2134
    2134 kernel/qobject.cpp: No such file or directory.
    in kernel/qobject.cpp
    I should clarify, I have a couple breakpoints set to the start of my default constructor, and the start of the main function. using next, I went along until it segfaulted. Had the constructor been called, I'd have hit the breakpoint at the constructor.
    Last edited by jacek; 12th September 2006 at 15:12. Reason: changed [ code ] to [ quote ] to allow wrapping

  11. #11
    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
    /usr/local/Trolltech/Qt-4.1.0/lib/libQtGui_debug.so.4
    /usr/local/Trolltech/Qt-4.1.0/lib/libQtCore_debug.so.4
    Is that the only Qt4 version you have on your system?

    Quote Originally Posted by Hydragyrum
    datagen.cpp:34: error: invalid conversion from `unsigned int' to `QTableWidget*
    I forgot to add casts:
    Qt Code:
    1. DataGen::DataGen() : m_munPhRanges( (QTableWidget*)0xdeadbeef ), m_munPkRanges( (QTableWidget*)0xcafebabe )
    To copy to clipboard, switch view to plain text mode 
    When it crashes just check whether these adresses are different.

    Do you do anything else (except for initialization and connections) with m_munPhRanges and m_munPkRanges? Maybe you delete them by accident?

  12. #12
    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

    pretty sure I don't delete them, let Qt take care of that when the class gets nuked.

    As far as I know, that's the only Qt4 version that exists on this machine.

    the tables are not even declared yet at the point of the crash, since the constructor isn't even called...but it's somehow entering the setUpConnections function, which is only called from within the constructor...and I'm not sure why...

    all optimization flags are off, btw.
    Last edited by Hydragyrum; 12th September 2006 at 15:35.

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.