I'm not quite sure if this is a bug with Qt or Irrlicht but I've had a strange problem when using file selection dialogs in a Qt application with an Irrlicht widget.
I'm running Ubuntu 11.04 (64 bit) and I used the code from this site: http://www.matrix44.net/blog/?p=389 (also available somewhere on this forum) to set up a Qt window with an Irrlicht widget inside it. I'd decided to make a model viewer program and so I needed to have a file selection dialog in order to select a model to open. The file selection dialog worked perfectly until I browsed to a folder containing some images and as soon as it tried to load the preview icons for those images I had a segmentation fault. I tested it again with image previews turned off and everything worked perfectly.
I have no idea why this would happen, since I didn't make any reference to it in my code. I even tried getting rid of all my code and just using the example from that site plus an added QFileDialog and it still had the same problem.
Has anyone else had a similar problem and does anyone know what might be causing it?
Irrlicht + Qt QFileDialog can cause a segmentation fault
-
- Posts: 18
- Joined: Sat Oct 03, 2009 7:14 am
- Location: Brisbane, Australia
- Contact:
There is an actual irrlicht widget here -> http://www.matrix44.net/blog/?p=437
-
- Posts: 18
- Joined: Sat Oct 03, 2009 7:14 am
- Location: Brisbane, Australia
- Contact:
Yes, and I tried adding a button that opens a file selection dialog to that program and I still run into the same error. I.e. whenever you browse to a directory containing images and it attempts to load the preview for an image you get a segmentation fault.
If you'd like to see exactly what I did, I just got that program (Irrtest17) and added this code to the constructor in Application.cpp:
added a function that creates a file open dialog to Application.cpp:
And added a declaration for it (void openFile();) in Application.h at line 23.
I also added to the begining of Application.h
If you'd like to see exactly what I did, I just got that program (Irrtest17) and added this code to the constructor in Application.cpp:
Code: Select all
QPushButton *button = new QPushButton( this );
button->setText( "Open file" );
button->show();
connect( button, SIGNAL( clicked() ), this, SLOT( openFile()) );
Code: Select all
void Application::openFile()
{
QString fileName = QFileDialog::getOpenFileName(this,
"Open 3D Model");
}
I also added
Code: Select all
#include <QtGui/QPushButton>
#include <QtGui/QFileDialog>
My website - Miscreant Software
What your trying to do is a little bit tricky but here is some example code from a media player that I was coding. It might help.
Whats happening isn't a bug it's just that the way that QDir works is kinda tricky.
I want to help you solve your problem but I cant right now because I hurt my back and I can't sit down in front of my computer for longer than a few seconds.
Hope that helps.
Whats happening isn't a bug it's just that the way that QDir works is kinda tricky.
I want to help you solve your problem but I cant right now because I hurt my back and I can't sit down in front of my computer for longer than a few seconds.
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <taglib/fileref.h>
#include <taglib/tag.h>
#include "lastfm.h"
#include <QStringList>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ml = new WidgetMarqueeLabel;
ml->setTextFormat(Qt::RichText);
ui->horizontalLayout_4->addWidget(ml);
ml->setAlignment(Qt::AlignVCenter);
ml->setText("Booomer Media Player v0.0.1a");
ml->setFont(QFont("Arial", 12, 12));
ml->setSpeed(1);
play = new QAction(QIcon::fromTheme("media-playback-start"), QString("&Play"), ui->mainToolBar);
ui->mainToolBar->addAction(play);
pause = new QAction(QIcon::fromTheme("media-playback-pause"), QString("&Pause"), ui->mainToolBar);
ui->mainToolBar->addAction(pause);
stop = new QAction(QIcon::fromTheme("media-playback-stop"), QString("&Stop"), ui->mainToolBar);
ui->mainToolBar->addAction(stop);
const char* vlc_args[] = {
"--ignore-config", /* Don't use VLC's config */
"--plugin-path=/usr/include/vlc/plugins","--LIBS+=/usr/lib -lvlc" };
QList<const char *> a;
a.append(*vlc_args);
instance = new VlcInstance(a, this);
volSlider = new VlcVolumeSlider;
volSlider->setVolume(54);
volSlider->setMaximumWidth(200);
ui->horizontalLayout_2->addWidget(volSlider);
seeker = new VlcSeekWidget;
ui->horizontalLayout->addWidget(seeker);
player = new VlcMediaPlayer();
dir = new QDir;
model = new QFileSystemModel;
model->setRootPath("");
QStringList filters;
filters << "*.mp3" << "*.mp4" << "*.wav";
model->setNameFilters ( filters );
model->setFilter(QDir::Files);
model->setNameFilterDisables(false);
ui->listView->setModel(model);
ui->listView->setRootIndex(model->index(dir->currentPath()));
ui->listView->setStyleSheet("QListView::item:hover {border-radius: 7px; background-color:"
"rgba(88, 88, 88, 75%);color: #fff; opacity: 200;}"
"QListView::item:selected {border-radius: 7px; background-color:"
"rgba(88, 88, 88, 75%);color: #fff; opacity: 200;}");
ui->qwwbuttonlineedit->setText(dir->currentPath());
dialog = new QFileDialog;
connect(ui->qwwbuttonlineedit, SIGNAL(buttonClicked()), this, SLOT(dirChanged()));
connect(ui->listView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(iconClicked(QModelIndex)));
connect(pause, SIGNAL(triggered()), player, SLOT(pause()));
connect(play, SIGNAL(triggered()), player, SLOT(play()));
connect(stop, SIGNAL(triggered()), player, SLOT(stop()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::iconClicked(QModelIndex indx)
{
QString file = indx.data(Qt::DisplayRole).toString();
TagLib::FileRef f(file.toLatin1().data());
TagLib::Tag *tag = f.tag();
QString year, track;
ml->setText(TStringToQString(tag->title()) + " - " + TStringToQString(tag->artist()));
ui->lineEdit->setText(TStringToQString(tag->title()));
ui->lineEdit_2->setText(TStringToQString(tag->artist()));
ui->lineEdit_3->setText(TStringToQString(tag->album()));
ui->lineEdit_4->setText(year.setNum(tag->year()));
ui->lineEdit_5->setText(TStringToQString(tag->comment()));
ui->lineEdit_6->setText(track.setNum(tag->track()));
ui->lineEdit_7->setText(TStringToQString(tag->genre()));
player->open(indx.data(Qt::DisplayRole).toString());
ui->statusBar->showMessage("Playing " + indx.data(Qt::DisplayRole).toString() );
}
void MainWindow::dirChanged()
{
QString path;
path = dialog->getExistingDirectory(this,"Choose a dir to open");
ui->qwwbuttonlineedit->setText(path);
ui->listView->setRootIndex(model->index(path));
}