Results 1 to 6 of 6

Thread: Loading text with the first line ending with tabulator causes crash

  1. #1
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Loading text with the first line ending with tabulator causes crash

    Hello,

    i've got a program loading several text files and displaying the content using a QLabel embedded in a QScrollarea.
    This works quite fine, except when I load a file thats first line ends with a tab. The Text file is still loaded correctly, but when resizing the Label or changing the Stylesheet of the Scrollarea I receive a segfault.

    The Objects are all instatieated properly and I can also view other textfiles before producing the crash.


    I have no idea, what the actual problem is, i don't even have an idea, what to search for, so maybe someone can give me a hand what to try next.
    Last edited by Zorki; 15th June 2011 at 19:53.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Loading text with the first line ending with tabulator causes crash

    To diagnose this problem, I would create a tiny test program that simply puts a QLabel in a QScrollArea, and *manually* set the label's text to a string containing tabs, newlines, whatever. If that works correctly without a crash, then you know the problem must be somewhere else in your code, and the crash is just a side effect of something going wrong earlier in the code that trashes the label's internals.

  3. #3
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Loading text with the first line ending with tabulator causes crash

    I tried to make a small example containing the critical code, but it is not exact the same, since the program already crashes loading the file.

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QtGui>
    6.  
    7. class MainWindow : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. MainWindow(QWidget *parent = 0);
    13. ~MainWindow();
    14.  
    15. private:
    16. QLabel *label;
    17. };
    18.  
    19. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. this->label = new QLabel();
    7. this->setCentralWidget(label);
    8.  
    9.  
    10. QString filePath("crash.txt");
    11. QFile f(filePath);
    12. if(f.open(QFile::ReadOnly)) {
    13. QTextStream s(&f);
    14.  
    15. this->label->setText(s.readAll()); // Crash
    16. } else {
    17. this->label->setText(tr("File ") + filePath + tr(" could not be read."));
    18. }
    19. }
    20.  
    21. MainWindow::~MainWindow()
    22. {
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

    Just calling s.readAll() works fine.
    I attached the file that causes the crash. Again everything works, if i delete the tab.
    Attached Files Attached Files

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Loading text with the first line ending with tabulator causes crash

    No crash on my machine ( Windows 7, Qt 4.5.2 ).
    Maybe run through debugger and check backtrace.

  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: Loading text with the first line ending with tabulator causes crash

    No crash here with Qt 4.7.2 on Linux. Using the debugger after a full, clean, debug build is a good start. When (if) it crashes read down the backtrace until you find the line in your code that triggered the crash. Look at the parameters you pass at that point for clues.

    Also try just the following program to eliminate file handling and other aspects:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtGui/QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QLabel l("d\t\n");
    9. l.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to ChrisW67 for this useful post:

    Zorki (16th June 2011)

  7. #6
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Loading text with the first line ending with tabulator causes crash

    The shorter program posted by Chris crashes, too. (I am using Qt version 4.6.3 on Linux).

    The backtrace suggests that l.show(); causes the crash, but there are no parameters hinting at the problem.

    Here is the backtrace:
    Qt Code:
    1. 0 QTextLine::layout_helper(int) /usr/lib/libQtGui.so.4 0 0xb77f1fae
    2. 1 QTextLine::setLineWidth(double) /usr/lib/libQtGui.so.4 0 0xb77f3dbc
    3. 2 ?? /usr/lib/libQtGui.so.4 0 0xb76d8c0a
    4. 3 ?? /usr/lib/libQtGui.so.4 0 0xb76d99c1
    5. 4 QFontMetrics::boundingRect(QRect const&, int, QString const&, int, int*) const /usr/lib/libQtGui.so.4 0 0xb77c3f3b
    6. 5 ?? /usr/lib/libQtGui.so.4 0 0xb79c5fd1
    7. 6 QLabel::minimumSizeHint() const /usr/lib/libQtGui.so.4 0 0xb79c6416
    8. 7 QLabel::sizeHint() const /usr/lib/libQtGui.so.4 0 0xb79c653b
    9. 8 QWidgetPrivate::adjustedSize() const /usr/lib/libQtGui.so.4 0 0xb75bddd9
    10. 9 QWidget::adjustSize() /usr/lib/libQtGui.so.4 0 0xb75c4c3d
    11. 10 QWidget::setVisible(bool) /usr/lib/libQtGui.so.4 0 0xb75cdb80
    12. 11 QWidget::show qwidget.h 485 0x08048992
    13. 12 main main.cpp 9 0x080488ad
    To copy to clipboard, switch view to plain text mode 

    Same in the program above: w.show() leads to the segfault.

    It seems that this behavior was already detected as a bug in version 4.6.3 and fixed in 4.7.1
    (Check http://bugreports.qt.nokia.com/browse/QTBUG-13546 and http://bugreports.qt.nokia.com/browse/QTBUG-11427)

    In fact I should have found this earlier on my own, so thank you for helping me nevertheless.

Similar Threads

  1. loadFromData() of QImage crash in case of .gif loading
    By santosh.kumar in forum Qt Programming
    Replies: 11
    Last Post: 9th March 2011, 12:52
  2. loadFromData() of QImage -crash in case of .gif loading
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2011, 12:56
  3. QPlainText Edit and text lines
    By aarelovich in forum Qt Programming
    Replies: 4
    Last Post: 23rd June 2010, 14:09
  4. plot with hor. lines and text
    By hugo vanwoerkom in forum Qwt
    Replies: 2
    Last Post: 10th March 2010, 18:00
  5. I want to get lines of text
    By newplayer in forum Qt Programming
    Replies: 11
    Last Post: 29th July 2008, 10:03

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.