Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6897343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:09:26+00:00 2026-05-27T07:09:26+00:00

It maybe a bug. Please read webclectic answer. If QFileInfo(filename) loss ‘/’, QDir::absolutePath will

  • 0

It maybe a bug. Please read webclectic answer.

If QFileInfo(filename) loss ‘/’, QDir::absolutePath will return the parent string. Like below code.

QFileInfo file("e:/QtExample/mytest/out/res/res1/");
QFileInfo file_no("e:/QtExample/mytest/out/res/res1");

QDir dirFile = file.absoluteDir();
QDir dirFile_no = file_no.absoluteDir();

QString strDirFile = dirFile.absolutePath(); //"E:/QtExample/mytest/out/res/res1
QString strDirFile_no = dirFile_no.absolutePath(); //"E:/QtExample/mytest/out/res

I found it with my QTreeView. My code will call the slot from QTreeView::clicked signals

connect(ui.m_pView,SIGNAL(clicked(QModelIndex)),this,SLOT(myClicked(QModelIndex)));

the slot will get the QModelIndex, then I use QFileSystemMode::fileInfo get the QFileInfo.

QFileInfo rFileInfo = m_model.fileInfo(index);
QDir absDir = rFileInfoDir.absoluteDir();    

But the return of QFileInfo always return “e:/QtExample/mytest/out/res/res”, so If I call QFileInfo::absoluteDir get the directory, the directory is the parent of “res1”.So I will get wrong entrylst from my hope directory.

Should I add the ‘/’ after the absoluteFilePath() to get the right QDir?

And why strDirPath equal “E:/QtExample/mytest/out/res/res1”, but rDir will list the “res” directory entrylist?

//rFileInfoDir == E:/QtExample/mytest/out/res/res1
QString strDirPath = rFileInfoDir.absoluteFilePath();
QDir rDir = rFileInfoDir.absoluteDir();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:09:27+00:00Added an answer on May 27, 2026 at 7:09 am

    If you go deep into the absoluteDir() function call you will see why this happens. In Windows the fileName function in qfsfileengine_win.cpp is called. In this function there is this code part:

    if (file == AbsolutePathName) {
            int slash = ret.lastIndexOf(QLatin1Char('/'));
            if (slash < 0)
                return ret;
            else if (ret.at(0) != QLatin1Char('/') && slash == 2)
                return ret.left(3);      // include the slash
            else
                return ret.left(slash > 0 ? slash : 1);
    }
    

    You can see that it returns the part of the string left of the last separator. I don’t know if this is the desired behavior or a bug. Maybe you could issue a Qt bug for this. The documentation is not clear on this matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found strange bug (maybe). When I send parameters to $.ajax in a form
Can somebody please explain this IE7 bug to me? It occurs in Standards and
I've never seen this, maybe it is a bug in the jvm? I added
Please read this entire question before you try to mark this as too controversial.
I'd really like some help with the following MySQL / PHP problem (maybe bug?)
What exactly does this mean -- Maybe IRB bug!? What does that tell me
I've found what I think may be a bug with Ivar and Objective-C runtime.
Maybe I just don't know .NET well enough yet, but I have yet to
Maybe the need to do this is a 'design smell' but thinking about another
Maybe this is a dumb question, but is there any way to convert a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.