[SOLVED] How to set the QDir to current open file ?

  • Hi Friends,
    I have the following code

    //Code to pull up the find file dialog
    QDir dir;
    QString fileName;

    if (fileName.isNull())
        fileName = QFileDialog::getOpenFileName(this,
            tr("Open File"), "", "C++ Files (*.cxx *.cpp *.h)");
    if (!fileName.isEmpty())
        QFile file(fileName);
        if (file.open(QFile::ReadOnly | QFile::Text))
        highlighter = new Highlighter(textEdit->document());

    //Code to get all files in the current directory
    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    dir.setSorting(QDir::Size | QDir::Reversed);

    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i)
    QFileInfo fileInfo = list.at(i);
    dirInfo << qPrintable(QString("%1").arg(fileInfo.fileName()));

    qDebug() << "dir info :" << dirInfo;
    QString callgraphfiledir, cfgfiledir;
    //Set path for call graph and control flow graph
    for (int dirindex = 0; dirindex < dirInfo.size(); dirindex ++)
        QString tmp = dirInfo[dirindex];
        if (tmp.endsWith(".d", Qt::CaseInsensitive))
            callgraphfiledir = tmp;
        if (tmp.endsWith(".cfg", Qt::CaseInsensitive))
            cfgfiledir = tmp;


    However dir is set to the directory where the executable is running. How do i set it to the path where the .cxx / .cpp / .h file lies ?

    Thanks for your help.

Log in to reply