Problem with boost/filesystem in Qt

Not sure if should post this in Qt forum or boost forum or here. Anyway, Im compiling with MSVC 2010 and using Boost 1.59. I am having trouble setting the path variable in boost/filesystem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <QDebug>
#include <QFileDialog>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <iostream>
#include <cstring>

void MainWindow::onBrowse()
{
    //open file select and set selected directory equal to browseDir
    browseDir = QFileDialog::getExistingDirectory(this, "Choose Working Directory",
                                                  "/home", QFileDialog::ShowDirsOnly);
    ui->browseEdit->setText(browseDir);//set browseEdit (a QString) text to selected directory
    file = browseDir.toStdString();
 //file is  a string which I tried using as a workaround before posting here
    boost::filesystem::path p(file.c_str());//use boost filesystem to make path variable. 
//I originally passed file as just a string and that didn't work either
}


The program crashes when a directory is selected and I cannot figure out what is going on. Any help appreciated
Last edited on
On what line exactly does the code crash?

My current guess is that either ui or ui->browseEdit is not initialized, but currently I cannot actually prove this given the current code. I don't really see any other problems on the other lines. Your boost::filesystem::path constructor seems fine.
Figured it out,

what I had was fine and simply running "Rebuild All" (rather than just "build") in QtCreator somehow got things working correctly.

Topic archived. No new replies allowed.