Results 1 to 9 of 9

Thread: SIGSESV error

  1. #1
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default SIGSESV error

    I'm trying to create a simple binary to decimal to hexadecimal appplication..
    My code seems to be compiling but each time..I'm getting a SIGSESV error. What am I doing wrong? Thanks.


    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "ByteConvertorDialog.h"
    3.  
    4. int main(int argc,char* argv[])
    5. {
    6. QApplication a(argc,argv);
    7.  
    8. ByteConvertorDialog c;
    9. c.setAttribute(Qt::WA_QuitOnClose);
    10. c.show();
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    newByte.cpp
    Qt Code:
    1. #include "ByteConvertorDialog.h"
    2. #include<QLabel>
    3. #include<QLineEdit>
    4. #include<QPushButton>
    5. #include<QGridLayout>
    6. #include<QVBoxLayout>
    7. #include<QHBoxLayout>
    8.  
    9. ByteConvertorDialog::ByteConvertorDialog()
    10. {
    11. QVBoxLayout * mainLayout = new QVBoxLayout(this);
    12. QGridLayout * editLayout = new QGridLayout;
    13. QHBoxLayout * pushButton = new QHBoxLayout;
    14.  
    15. mainLayout -> addLayout(editLayout);
    16. mainLayout -> addStretch();
    17. mainLayout ->addLayout(pushButton);
    18.  
    19. QLabel * bin = new QLabel("Binary");
    20. QLabel * dec = new QLabel("Decimal");
    21. QLabel * hex = new QLabel("Hexadecimal");
    22. decEdit = new QLineEdit;
    23. binEdit = new QLineEdit;
    24. hexEdit = new QLineEdit;
    25. QPushButton *button = new QPushButton("Quit");
    26.  
    27. editLayout ->addWidget(bin,0,0);
    28. editLayout ->addWidget(dec,1,0);
    29. editLayout ->addWidget(hex,2,0);
    30. editLayout ->addWidget(binEdit,0,1);
    31. editLayout ->addWidget(decEdit,1,1);
    32. editLayout ->addWidget(hexEdit,2,1);
    33.  
    34. pushButton ->addStretch();
    35. pushButton ->addWidget(button);
    36.  
    37. button ->setDefault(true);
    38.  
    39. connect(button,SIGNAL(clicked()),this,SLOT(accept()));
    40. connect(decEdit,SIGNAL(textChanged(const QString&)),this,SLOT(decChanged(const QString&)));
    41. connect(binEdit,SIGNAL(textChanged(const QString&)),this,SLOT(binChanged(const QString&)));
    42. connect(hexEdit,SIGNAL(textChanged(const QString&)),this,SLOT(hexChanged(const QString&)));
    43.  
    44. }
    45.  
    46. void ByteConvertorDialog::decChanged(const QString &newValue)
    47. {
    48. bool ok;
    49. int num= newValue.toInt(&ok);
    50. binEdit->setText(QString::number(num,2));
    51. hexEdit->setText(QString::number(num,16));
    52.  
    53. }
    54. void ByteConvertorDialog::binChanged(const QString &newValue)
    55. {
    56. bool ok;
    57. int num= newValue.toInt(&ok);
    58. decEdit->setText(QString::number(num,10));
    59. hexEdit->setText(QString::number(num,16));
    60.  
    61. }
    62. void ByteConvertorDialog::hexChanged(const QString &newValue)
    63. {
    64. bool ok;
    65. int num= newValue.toInt(&ok);
    66. binEdit->setText(QString::number(num,2));
    67. decEdit->setText(QString::number(num,10));
    68.  
    69. }
    To copy to clipboard, switch view to plain text mode 

    byteConvertorDialog.h
    Qt Code:
    1. #ifndef BYTECONVERTORDIALOG_H
    2. #define BYTECONVERTORDIALOG_H
    3. #include<QObject>
    4. #include<QDialog>
    5. #include<QLineEdit>
    6. class QLineEdit;
    7.  
    8. class ByteConvertorDialog:public QDialog
    9. { Q_OBJECT
    10. public:
    11. ByteConvertorDialog();
    12. private:
    13. QLineEdit * decEdit;
    14. QLineEdit * binEdit;
    15. QLineEdit * hexEdit ;
    16. private slots:
    17. void decChanged(const QString&);
    18. void binChanged(const QString&);
    19. void hexChanged(const QString&);
    20. };
    21. #endif // BYTECONVERTORDIALOG_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SIGSESV error

    At a guess, when you programatically change the values inside your handler slots you trigger a cascade of signals. Perhaps you want the QLineEdit::textEdited() signal instead.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SIGSESV error

    If the calculations are correct, the signals will not be emitted as changing text to the same text doesn't cause textChanged() signal to be emitted.

    @cipher1729: Use a debugger to see where your code crashes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: SIGSESV error

    Hi..
    Changing textChanged to textEdited solved the problem..
    In all probability calling setText also caused textChanged to be called..so there was a cascade of signals..
    Thanks to both the repliers

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SIGSESV error

    With the code as is the edit boxes do not function correctly before it crashes. I put a debug statement at the top of each slot: and started the program:
    Qt Code:
    1. // Press 1 in binary box
    2. binChanged "1"
    3. decChanged "1"
    4. hexChanged "1"
    5. // 1 displayed in all boxes
    6. // Press 1 in binary box
    7. binChanged "11"
    8. decChanged "11"
    9. binChanged "1011"
    10. decChanged "1011"
    11. binChanged "1111110011"
    12. decChanged "1111110011"
    13. binChanged "1000010001110100011000101111011"
    14. decChanged "0"
    15. binChanged "0"
    16. hexChanged "0"
    17. hexChanged "423a317b"
    18. hexChanged "3f3"
    19. hexChanged "b"
    20. // 0 displayed in all boxes
    To copy to clipboard, switch view to plain text mode 
    Clearly not the expected result. Press 2 in the binary box and and a stream of repeating debug messages ensues followed by:
    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. 0xb792381a in QTextEngine::itemize() const () from /usr/lib/qt4/libQtGui.so.4
    3. (gdb) bt
    4. #0 0xb792381a in QTextEngine::itemize() const ()
    5. from /usr/lib/qt4/libQtGui.so.4
    6. #1 0xb79256a3 in QTextEngine::attributes() const ()
    7. from /usr/lib/qt4/libQtGui.so.4
    8. #2 0xb792dbb1 in QTextLine::layout_helper(int) ()
    9. from /usr/lib/qt4/libQtGui.so.4
    10. #3 0xb792fc50 in QTextLine::setNumColumns(int) ()
    11. from /usr/lib/qt4/libQtGui.so.4
    12. #4 0xb792fcd1 in QTextLayout::endLayout() () from /usr/lib/qt4/libQtGui.so.4
    13. #5 0xb7afa381 in QLineControl::updateDisplayText(bool) ()
    14. from /usr/lib/qt4/libQtGui.so.4
    15. #6 0xb7afc780 in QLineControl::finishChange(int, bool, bool) ()
    16. from /usr/lib/qt4/libQtGui.so.4
    17. #7 0xb7afcada in QLineControl::internalSetText(QString const&, int, bool) ()
    18. from /usr/lib/qt4/libQtGui.so.4
    19. #8 0xb7af2f7d in QLineEdit::setText(QString const&) ()
    20. from /usr/lib/qt4/libQtGui.so.4
    21. #9 0x0804b959 in ByteConvertorDialog::binChanged (this=0xbfffe978,
    22. newValue=...) at ByteConvertorDialog.cpp:62
    To copy to clipboard, switch view to plain text mode 

    The conversions from string to int don't specify the base... this is the problem because it keeps changing the value because of incorrect conversions.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SIGSESV error

    Are you getting proper values? Because your code is definitely wrong. You are ignoring the number base and thus you get bogus values and thus you get a cascade of signals upon textChanged. As soon as you enter some other value than 0 or 1, your code will become unstable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SIGSESV error

    I'm following a book..as according to the example given..I put in validators to restrict the values entered in the line edits. But..yes..something's still wrong..the conversion is flawed. Like..decimal to binary works fine but not vice-versa.


    Qt Code:
    1. #include "ByteConvertorDialog.h"
    2. #include<QLabel>
    3. #include<QLineEdit>
    4. #include<QPushButton>
    5. #include<QGridLayout>
    6. #include<QVBoxLayout>
    7. #include<QHBoxLayout>
    8. #include<QValidator>
    9.  
    10. ByteConvertorDialog::ByteConvertorDialog()
    11. {
    12. QVBoxLayout * mainLayout = new QVBoxLayout(this);
    13. QGridLayout * editLayout = new QGridLayout;
    14. QHBoxLayout * pushButton = new QHBoxLayout;
    15.  
    16. mainLayout -> addLayout(editLayout);
    17. mainLayout -> addStretch();
    18. mainLayout ->addLayout(pushButton);
    19.  
    20. QLabel * bin = new QLabel("Binary");
    21. QLabel * dec = new QLabel("Decimal");
    22. QLabel * hex = new QLabel("Hexadecimal");
    23. decEdit = new QLineEdit;
    24. binEdit = new QLineEdit;
    25. hexEdit = new QLineEdit;
    26. QPushButton *button = new QPushButton("Quit");
    27.  
    28. editLayout ->addWidget(bin,0,0);
    29. editLayout ->addWidget(dec,1,0);
    30. editLayout ->addWidget(hex,2,0);
    31. editLayout ->addWidget(binEdit,0,1);
    32. editLayout ->addWidget(decEdit,1,1);
    33. editLayout ->addWidget(hexEdit,2,1);
    34.  
    35. pushButton ->addStretch();
    36. pushButton ->addWidget(button);
    37.  
    38. button ->setDefault(true);
    39. QIntValidator* decValidator = new QIntValidator(0,255,decEdit);
    40. decEdit->setValidator(decValidator);
    41. QRegExpValidator* hexValidator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,2}"),hexEdit);
    42. hexEdit->setValidator(hexValidator);
    43. QRegExpValidator*binValidator = new QRegExpValidator(QRegExp("[01]{1,8}"),binEdit);
    44. binEdit->setValidator(binValidator);
    45.  
    46. connect(button,SIGNAL(clicked()),this,SLOT(accept()));
    47. connect(decEdit,SIGNAL(textEdited(const QString&)),this,SLOT(decChanged(const QString&)));
    48. connect(binEdit,SIGNAL(textEdited(const QString&)),this,SLOT(binChanged(const QString&)));
    49. connect(hexEdit,SIGNAL(textEdited(const QString&)),this,SLOT(hexChanged(const QString&)));
    50.  
    51. }
    52.  
    53. void ByteConvertorDialog::decChanged(const QString &newValue)
    54. {
    55. bool ok;
    56. int num= newValue.toInt(&ok);
    57. if (ok) {
    58. hexEdit->setText(QString::number(num, 16));
    59. binEdit->setText(QString::number(num, 2));
    60. } else {
    61. hexEdit->setText("");
    62. binEdit->setText("");
    63. }
    64.  
    65. }
    66. void ByteConvertorDialog::binChanged(const QString &newValue)
    67. {
    68. bool ok;
    69. int num= newValue.toInt(&ok);
    70. if (ok) {
    71. hexEdit->setText(QString::number(num, 16));
    72. decEdit->setText(QString::number(num));
    73. } else {
    74. hexEdit->setText("");
    75. decEdit->setText("");
    76. }
    77.  
    78. }
    79. void ByteConvertorDialog::hexChanged(const QString &newValue)
    80. {
    81. bool ok;
    82. int num= newValue.toInt(&ok);
    83. if (ok) {
    84. decEdit->setText(QString::number(num, 10));
    85. binEdit->setText(QString::number(num, 2));
    86. } else {
    87. decEdit->setText("");
    88. binEdit->setText("");
    89. }
    90.  
    91. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by cipher1729; 22nd June 2011 at 03:48.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SIGSESV error

    You need to pass the optional second argument to QString::toInt() to specify the base you are converting from.

  9. #9
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SIGSESV error

    That seems to have done it. thanks

Similar Threads

  1. no compile error, but error on run with QMenu QAction
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 11:05
  2. : error: [\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\V ideo.exe] Error 1
    By ranjit.kadam in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 1st May 2011, 22:11
  3. Replies: 3
    Last Post: 23rd January 2011, 12:15
  4. fatal error C1001: An internal error has occurred in the compiler
    By noodles in forum Installation and Deployment
    Replies: 0
    Last Post: 12th August 2010, 11:24
  5. Replies: 1
    Last Post: 25th October 2008, 19:18

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.