Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to set the QDir to current open file ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amban
    wrote on last edited by
    #1

    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))
            textEdit->setPlainText(file.readAll());
        findstring->setDisabled(false);
    
        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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      "QDir::cd()":http://doc.qt.nokia.com/stable/qdir.html#cd

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved