I have made a simple program that show directory listing in QTreeView using QFileSystemModel.
With a QPushButton the program is calling a slot that is making a new directory, but it never makes a new directory.
This is the slot that makes a new directory:
QModelIndex index=viewTreeForModel->currentIndex();
if (!index.isValid()) return;
QString filename=QInputDialog::getText(this, "Enter Name Dialog", "Enter name");
modelFile->mkdir(viewTreeForModel->currentIndex(), filename);
I dont get a error messages from the program when it runs.
Check the
QModelIndexreturned by mkdir is valid.You could also try
Then check the value of
success.As an aside, I would recommend renaming the variable
stringto something likenewfilename, it would make the code more readable.