PDA

View Full Version : Silly Question/A very silly question



seerofsorrow
21st September 2017, 21:57
I'm trying to make a directory in my system based off of input from the ui and I can't get the QString to take another QString injected into it. I'm trying to understand how to get that to work. If anybody could give me some insite I'd appreciate it. I have a LineEdit box in my ui called caseNumberText.

I initilized filename as "C:/Users/Administrator/Qt/"

My main has no errors in it and is a very basic template. the only problem i'm having with is my classy.cpp file:
#include "header.h"
#include "ui_gui.h"
#include <QTextStream>
#include <QString>
#include <QLineEdit>
#include <QFile>
#include <QDebug>
#include <QFileDialog>

Classy::Classy(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Classy)
{
ui->setupUi(this);
}

Classy::~Classy()
{
delete ui;
}

void Classy::on_caseNumberText_selectionChanged()
{
QString caseNumberText = ui->caseNumberText->text();
QString filename = "C:/Users/Administrator/Qt/"caseNumberText;

QDir dir(filename);
if (!dir->exists())
{
dir->mkpath(filename);
}
else
{
qDebug << caseNumberText << "already exsists";
}

}

d_stranz
21st September 2017, 23:24
QString filename = "C:/Users/Administrator/Qt/"caseNumberText;

How about looking at QString::operator+() or the equivalent QString::append()?


QString filename = QString( "C:/Users/Administrator/Qt/" ) + caseNumberText;
// or
QString filename = QString( "C:/Users/Administrator/Qt/" ).append( caseNumberText );


No silly questions, just silly answers.

Of course, once you get your string built, Windows probably won't actually let you create a directory under Administrators unless you are running your program with elevated permission. If you just click the icon for Qt Creator / Visual Studio, you aren't running that way, so any program you run from within the IDE or debugger won't have permission either.