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
#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
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.