Results 1 to 7 of 7

Thread: Program crashes on 64-bit systems

  1. #1
    Join Date
    Dec 2012
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Program crashes on 64-bit systems

    Hello everybody. I'm writing a rather simple program on Qt. While I was working on 32-bit Ubuntu everything worked fine but when I tried to run the code under 64-bit Ubuntu it crashes with SIGABRT. Here's the simplified code that shares the same problems. it's your basic QTableWidget-based file manager

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <stdhdr.h>
    5. class BrowserTable;
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. BrowserTable *m_pBrowserTable;
    22. };
    23.  
    24. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. #include <stdhdr.h>
    2.  
    3. MainWindow::MainWindow(QWidget *parent) :
    4. QMainWindow(parent),
    5. ui(new Ui::MainWindow)
    6. {
    7. ui->setupUi(this);
    8.  
    9. m_pBrowserTable = new BrowserTable(this, ui, "/");
    10.  
    11.  
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete m_pBrowserTable;
    17. if(ui)
    18. delete ui;
    19. }
    To copy to clipboard, switch view to plain text mode 

    browsertable.h
    Qt Code:
    1. #ifndef BROWSERTABLE_H
    2. #define BROWSERTABLE_H
    3.  
    4. #include "stdhdr.h"
    5.  
    6. class MainWindow;
    7. class BrowserTable : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit BrowserTable(MainWindow *pMainWindow, Ui::MainWindow *pui, QString top_level, QObject *parent = 0);
    12. void SetupTable();
    13. ~BrowserTable();
    14.  
    15. public slots:
    16. void FillTableAsTable(QString);
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20. MainWindow *m_pMainWindow;
    21.  
    22. };
    23.  
    24. #endif // BROWSERTABLE_H
    To copy to clipboard, switch view to plain text mode 

    browsertable.cpp
    Qt Code:
    1. #include "browsertable.h"
    2.  
    3. BrowserTable::BrowserTable(MainWindow *pMainWindow, Ui::MainWindow *pui, QString top_level, QObject *parent) :
    4. QObject(parent)
    5. {
    6. ui =pui;
    7. m_pMainWindow=pMainWindow;
    8.  
    9. SetupTable();
    10. }
    11.  
    12. BrowserTable::~BrowserTable()
    13. {
    14.  
    15. }
    16.  
    17. void BrowserTable::SetupTable()
    18. {
    19. ui->table_browser->setColumnCount(4);*
    20. QHeaderView *headerView = ui->table_browser->horizontalHeader();
    21. headerView->setResizeMode(1, QHeaderView::Stretch);
    22. headerView->setResizeMode(0, QHeaderView::Fixed);
    23. headerView->setResizeMode(2, QHeaderView::Fixed);
    24. headerView->setClickable(false);
    25.  
    26. QTableWidgetItem *h_item1 = new QTableWidgetItem(" ");
    27.  
    28. QTableWidgetItem *h_item2 = new QTableWidgetItem("Name");
    29. QTableWidgetItem *h_item3 = new QTableWidgetItem("Type");
    30. QTableWidgetItem *h_item4 = new QTableWidgetItem("Size");
    31. ui->table_browser->setHorizontalHeaderItem(0, h_item1);
    32. ui->table_browser->setHorizontalHeaderItem(1, h_item2);
    33. ui->table_browser->setHorizontalHeaderItem(2, h_item3);
    34. ui->table_browser->setHorizontalHeaderItem(3, h_item4);
    35. ui->table_browser->horizontalHeader()->setVisible(true);
    36. ui->table_browser->verticalHeader()->setVisible(false);
    37. ui->table_browser->setColumnWidth(0, 20);
    38. ui->table_browser->setShowGrid(false);
    39.  
    40. ui->table_browser->setSelectionMode(QAbstractItemView::SingleSelection);
    41. ui->table_browser->setSelectionBehavior(QAbstractItemView::SelectRows);
    42.  
    43. FillTableAsTable("/");
    44. }
    45.  
    46. void BrowserTable::FillTableAsTable(QString path)
    47. {
    48. ui->table_browser->setHidden(false);
    49. QDir current_dir(path);
    50.  
    51. QFileInfoList file_list = current_dir.entryInfoList();
    52. if (file_list.count()==0)
    53. {
    54. return;
    55. }
    56.  
    57. ui->table_browser->clear();
    58. ui->table_browser->setRowCount(file_list.count());
    59.  
    60. for (int i=0; i<file_list.count(); i++)
    61. {
    62. QIcon myicon = prov->icon(file_list.at(i));
    63.  
    64.  
    65. item1->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
    66. item1->setIcon(myicon);
    67. item3->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
    68.  
    69. ui->table_browser->setItem(i, 1, item1);
    70. ui->table_browser->setItem(i, 0, item2);
    71. ui->table_browser->setItem(i, 2, item3);
    72. ui->table_browser->setItem(i, 3, item4);
    73.  
    74. }
    75. }
    To copy to clipboard, switch view to plain text mode 

    The problem seems to be with the ui pointer in the Browsertable but I have no idea how to fix the issue while keeping the same class structure. Any hel would be appreciated.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Program crashes on 64-bit systems

    Which line does it crash?

    BTW there is an extra '*' at browsertable.cpp#19 (I guess copy paste thing)
    Last edited by Santosh Reddy; 4th February 2013 at 22:00.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2012
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes on 64-bit systems

    Quote Originally Posted by Santosh Reddy View Post
    Which line does it crash?
    It crashes basically everywhere. In this particular code it does so in line 63 of browsertable.cpp after several iterations. If I comment this line it crashes in line 57. If I completeely comment FillTableAsTable function call then it crashes in mainwindow.cpp in the destructor if I remove ui existance check.

    Quote Originally Posted by Santosh Reddy View Post
    BTW there is an extra '*' at browsertable.cpp#19 (I guess copy paste thing)
    Yes, it is. Unfortunately it's too late for me to edit

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Program crashes on 64-bit systems

    Does it crash even if you step the complete code?

    Just another observation, add a "delete prov", in the for loop;
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Dec 2012
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes on 64-bit systems

    Quote Originally Posted by Santosh Reddy View Post
    Does it crash even if you step the complete code?
    Well it is a complete code, it misses only main.cpp which is generic and stdhdr.h which only has various includes. If by the complete code you mean the main program I'm doing than it crashes in a somewhat different place but with the same syptoms.
    And if by step you mean pressing f10 (sorry, I'm pretty new to programmers' forums) then yes, it does. It gives me munmap_chunk(): invalid pointer error if that helps

    Quote Originally Posted by Santosh Reddy View Post
    "delete prov", in the for loop
    Good idea. It didn't solve the problem but thanks
    Last edited by WereWind; 5th February 2013 at 08:52.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Program crashes on 64-bit systems

    Good idea. It didn't solve the problem but thanks
    It was not to solve the crash problem, It was just to avoid memory leak

    One last thing which I can suggest is, Make sure you Clean All, and Rebuild the code a fresh. (I insist make sure you are using correct file paths to build)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Dec 2012
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes on 64-bit systems

    Quote Originally Posted by Santosh Reddy View Post
    One last thing which I can suggest is, Make sure you Clean All, and Rebuild the code a fresh. (I insist make sure you are using correct file paths to build)
    Just did that. still the same crash. Well, thanks for the help anyway.
    PS. If I upload the whole project here, can anybody test it on their own 64-bit system? Maybe it's something on my end after all

Similar Threads

  1. Program crashes on OS X Lion
    By fyodor in forum Newbie
    Replies: 1
    Last Post: 31st October 2011, 06:18
  2. Program crashes
    By Fallen_ in forum Qt Programming
    Replies: 49
    Last Post: 20th September 2010, 01:41
  3. Program crashes while trying to do a check in constructor
    By hakermania in forum Qt Programming
    Replies: 5
    Last Post: 1st September 2010, 10:15
  4. program crashes (QtTestRunner)
    By fmariusd in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 09:27
  5. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09

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.