PDA

View Full Version : Trying to merge QDirModel and QMediaPlayer



Bloodshedder
20th October 2015, 08:32
Hi, im new to this forum and to QT.

I consider myself a below average C++ programmer

Im trying to mergue to diferent mini projects to one. They work perfectly separated but when i merge them the program crashes.

The QDirModel was created using a Base Clase QDialog and the QMediaPlayer was created with Base class QMainWindow.
The treeview was created with a mainwindow.ui


The code goes as follows :
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),

ui(new Ui::MainWindow)
{
ui->setupUi(this);

//-----------------Tree Archives
model =new QDirModel(this);
model->setReadOnly(false);
model->setSorting(QDir::DirsFirst | QDir::IgnoreCase| QDir::Name);

ui->treeView->setModel(model);

QModelIndex index= model->index("C:/");

ui-> treeView->expand(index);
ui-> treeView->scrollTo(index);
ui->treeView->setCurrentIndex(index);
ui->treeView->resizeColumnToContents(0);
//-----------------Tree Archives end


//-----------------Video Start


player = new QMediaPlayer(this);

vw=new QVideoWidget(this);


player->setVideoOutput(vw);
setGeometry(100,100,1000,700);
vw->setGeometry(10,50,640,320);
//-----------------Video Start end

Originally i thought it was a problem with the video taking up all the video space so i decided to resize it. But it didnt work.

any leads or pointers on the cause of the problem!?
Thanks!

Bloodshedder
21st October 2015, 04:18
Any help? please!

jefftee
21st October 2015, 04:36
Any help? please!It might help if you elaborated on where your program crashes and show the stack trace.

Bloodshedder
21st October 2015, 04:56
if i open them separately they work fine, but when i combine the codes it crashes!

this is the lay out of that i want to sorta display
11460

To be able to see that picture i had to comment this part of the code

// ui->treeView->setModel(model);

if i uncoment that line of code this happens

11461

jefftee
21st October 2015, 05:37
You need to run your program in debug mode using Qt Creator, learn how to set breakpoints and inspect variables, etc. When you step through the execution of your code, then you can begin to try to figure out what's wrong.

My first guess is that you need to set the model's index before adding the model to the view.

Bloodshedder
21st October 2015, 06:43
Trying to google whats a model's index... thanks still stuck though

Added after 33 minutes:

Set a breaking point and did step over till the error appeared and this showed up!

11462

Bloodshedder
21st October 2015, 19:22
please help

Bloodshedder
22nd October 2015, 04:27
ran the code on ubuntu, just changed the directory to linux type and it worked... im baffled

Caolan O'Domhnaill
24th October 2015, 02:15
ran the code on ubuntu, just changed the directory to linux type and it worked... im baffled

QModelIndex index= model->index("C:/"); // Windows does not use the slash '/'. It uses Backslash '\'. Linux uses slash '/' which might be why when you switches it likes it.

REMEBER: C/C++ sees the backslash as a an escape character so when writing paths in C/C++ for windows you need to do a double escape for it to see the backslash so you should do:

QModelIndex index= model->index("C:\\");