PDA

View Full Version : IDE-like interface



ntzrmtthihu777
8th August 2014, 18:52
Greetings, I'm a bit of a hobbyist programmer in a few languages, and am now finally stepping up to real application developement.
Was giving Qt a shot and I must say its very good for rapid GUI building on linux.

What I'm working on is pretty analogous to an IDE, in that you chose a 'project file' which is read in and sets up the project paths and such.

I'm having issue with a portion of it, in that I can't figure out how to pass information from the project file into a subwindow of the application;
Current code:

void MainWindow::file_open_project()
{
QString projectFile = QFileDialog::getOpenFileName(
this, tr("Open Project"),
QStandardPaths::writableLocation(QStandardPaths::D ocumentsLocation),
tr("Project files (*.proj)"));
if(!projectFile.isEmpty())
{
load_project(projectFile);
}
}

void MainWindow::load_project(QString projectFile)
{
QFileInfo project(projectFile);
QString projectPath = project.absolutePath();
QSettings *projectSettings = new QSettings(projectPath+"/Project", QSettings::IniFormat, this);
this->archiveFile->append(projectSettings->value("Archive").toString());
}

void MainWindow::archiveAction()
{
ArchiveEditor *archiveEditor = new ArchiveEditor(this, &archiveFile);
archiveEditor->setAttribute(Qt::WA_DeleteOnClose);
archiveEditor->setAttribute(Qt::WA_ShowModal);
archiveEditor->show();
}

ArchiveEditor::ArchiveEditor(QWidget *parent, QString *file)
:QWidget(parent, Qt::Window)
{
setWindowTitle(tr("Archive Editor"));

loadScriptArchive(file);
}

void ArchiveEditor::loadArchive(const QString &file)
{
QFile archiveFile = QFile(file);
if (!archiveFile.open(QFile::ReadOnly))
{
QMessageBox::critical(this,
tr("File read error"), tr("Cannot open file: ") + file);
return;
}
}

ArchiveEditor obviously doesn't do much atm, I'm just trying to figure out how to pass something from the Project.ini file into a subwindow to tell it which archive to load.

anda_skoa
9th August 2014, 09:03
Aside from this not compliing due to trying to copy QFile, what is your actual question?

This looks more or less OK, though I wouldn't pass the QString as a pointer (it is a value class and can easily be copied) and making a dialog modal is a lot easier by just calling QDialog::exec(), i.e. not need to set the modality flag.

Cheers,
_

ntzrmtthihu777
9th August 2014, 14:14
Heh, I feel kinda dumb now; problem was I was parsing the settings file wrong; it had one of those ini [SubSections] and was not taking that into account XD