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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <stdhdr.h>
class BrowserTable;
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
BrowserTable *m_pBrowserTable;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <stdhdr.h>
class BrowserTable;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
BrowserTable *m_pBrowserTable;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include <stdhdr.h>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_pBrowserTable = new BrowserTable(this, ui, "/");
}
MainWindow::~MainWindow()
{
delete m_pBrowserTable;
if(ui)
delete ui;
}
#include <stdhdr.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_pBrowserTable = new BrowserTable(this, ui, "/");
}
MainWindow::~MainWindow()
{
delete m_pBrowserTable;
if(ui)
delete ui;
}
To copy to clipboard, switch view to plain text mode
browsertable.h
#ifndef BROWSERTABLE_H
#define BROWSERTABLE_H
#include "stdhdr.h"
class MainWindow;
class BrowserTable
: public QObject{
Q_OBJECT
public:
explicit BrowserTable
(MainWindow
*pMainWindow, Ui
::MainWindow *pui,
QString top_level,
QObject *parent
= 0);
void SetupTable();
~BrowserTable();
public slots:
private:
Ui::MainWindow *ui;
MainWindow *m_pMainWindow;
};
#endif // BROWSERTABLE_H
#ifndef BROWSERTABLE_H
#define BROWSERTABLE_H
#include "stdhdr.h"
class MainWindow;
class BrowserTable : public QObject
{
Q_OBJECT
public:
explicit BrowserTable(MainWindow *pMainWindow, Ui::MainWindow *pui, QString top_level, QObject *parent = 0);
void SetupTable();
~BrowserTable();
public slots:
void FillTableAsTable(QString);
private:
Ui::MainWindow *ui;
MainWindow *m_pMainWindow;
};
#endif // BROWSERTABLE_H
To copy to clipboard, switch view to plain text mode
browsertable.cpp
#include "browsertable.h"
BrowserTable
::BrowserTable(MainWindow
*pMainWindow, Ui
::MainWindow *pui,
QString top_level,
QObject *parent
) :{
ui =pui;
m_pMainWindow=pMainWindow;
SetupTable();
}
BrowserTable::~BrowserTable()
{
}
void BrowserTable::SetupTable()
{
ui->table_browser->setColumnCount(4);*
QHeaderView *headerView
= ui
->table_browser
->horizontalHeader
();
headerView->setClickable(false);
ui->table_browser->setHorizontalHeaderItem(0, h_item1);
ui->table_browser->setHorizontalHeaderItem(1, h_item2);
ui->table_browser->setHorizontalHeaderItem(2, h_item3);
ui->table_browser->setHorizontalHeaderItem(3, h_item4);
ui->table_browser->horizontalHeader()->setVisible(true);
ui->table_browser->verticalHeader()->setVisible(false);
ui->table_browser->setColumnWidth(0, 20);
ui->table_browser->setShowGrid(false);
FillTableAsTable("/");
}
void BrowserTable
::FillTableAsTable(QString path
) {
ui->table_browser->setHidden(false);
QFileInfoList file_list = current_dir.entryInfoList();
if (file_list.count()==0)
{
return;
}
ui->table_browser->clear();
ui->table_browser->setRowCount(file_list.count());
for (int i=0; i<file_list.count(); i++)
{
QIcon myicon
= prov
->icon
(file_list.
at(i
));
item1->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
item1->setIcon(myicon);
item3->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
ui->table_browser->setItem(i, 1, item1);
ui->table_browser->setItem(i, 0, item2);
ui->table_browser->setItem(i, 2, item3);
ui->table_browser->setItem(i, 3, item4);
}
}
#include "browsertable.h"
BrowserTable::BrowserTable(MainWindow *pMainWindow, Ui::MainWindow *pui, QString top_level, QObject *parent) :
QObject(parent)
{
ui =pui;
m_pMainWindow=pMainWindow;
SetupTable();
}
BrowserTable::~BrowserTable()
{
}
void BrowserTable::SetupTable()
{
ui->table_browser->setColumnCount(4);*
QHeaderView *headerView = ui->table_browser->horizontalHeader();
headerView->setResizeMode(1, QHeaderView::Stretch);
headerView->setResizeMode(0, QHeaderView::Fixed);
headerView->setResizeMode(2, QHeaderView::Fixed);
headerView->setClickable(false);
QTableWidgetItem *h_item1 = new QTableWidgetItem(" ");
QTableWidgetItem *h_item2 = new QTableWidgetItem("Name");
QTableWidgetItem *h_item3 = new QTableWidgetItem("Type");
QTableWidgetItem *h_item4 = new QTableWidgetItem("Size");
ui->table_browser->setHorizontalHeaderItem(0, h_item1);
ui->table_browser->setHorizontalHeaderItem(1, h_item2);
ui->table_browser->setHorizontalHeaderItem(2, h_item3);
ui->table_browser->setHorizontalHeaderItem(3, h_item4);
ui->table_browser->horizontalHeader()->setVisible(true);
ui->table_browser->verticalHeader()->setVisible(false);
ui->table_browser->setColumnWidth(0, 20);
ui->table_browser->setShowGrid(false);
ui->table_browser->setSelectionMode(QAbstractItemView::SingleSelection);
ui->table_browser->setSelectionBehavior(QAbstractItemView::SelectRows);
FillTableAsTable("/");
}
void BrowserTable::FillTableAsTable(QString path)
{
ui->table_browser->setHidden(false);
QDir current_dir(path);
QFileInfoList file_list = current_dir.entryInfoList();
if (file_list.count()==0)
{
return;
}
ui->table_browser->clear();
ui->table_browser->setRowCount(file_list.count());
for (int i=0; i<file_list.count(); i++)
{
QFileIconProvider *prov = new QFileIconProvider();
QIcon myicon = prov->icon(file_list.at(i));
QTableWidgetItem *item1 = new QTableWidgetItem();
QTableWidgetItem *item2 = new QTableWidgetItem();
QTableWidgetItem *item3 = new QTableWidgetItem();
QTableWidgetItem *item4 = new QTableWidgetItem();
item1->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
item1->setIcon(myicon);
item3->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
ui->table_browser->setItem(i, 1, item1);
ui->table_browser->setItem(i, 0, item2);
ui->table_browser->setItem(i, 2, item3);
ui->table_browser->setItem(i, 3, item4);
}
}
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.
Bookmarks