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

  • Home
  • SEARCH
  • 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 8972249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:10:22+00:00 2026-06-15T18:10:22+00:00

QDir *temp = new QDir(%USERPROFILE%); bool ok = temp->mkdir(abc); and it does not work.

  • 0
QDir *temp = new QDir("%USERPROFILE%");
bool ok = temp->mkdir("abc");

and it does not work.

  • 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-06-15T18:10:23+00:00Added an answer on June 15, 2026 at 6:10 pm

    For portable Qt code, use static method QProcessEnvironment::systemEnvironment():

    QProcessEnvironment env(QProcessEnvironment::systemEnvironment());
    QDir *temp = new QDir(env.value("USERPROFILE")); // returns empty string for unset variable
    bool ok = temp->mkdir("abc");
    

    Alternative, as suggested in a comment of the actual question, you can also use

    #include <cstdio>
    
    QString envValue(QString::fromLocal8bit(::getenv("USERPROFILE"))); // standard, yet deprecated in Windows...
    

    I’d prefer using the first alternative, letting Qt take care of character encoding stuff. If you want to use non-Qt functions, I think in Windows you should use getenv_s or _wgetenv_s to do this “properly”.

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

Sidebar

Related Questions

Okay, I have the following code: QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir::currentPath()); model->setFilter(QDir::Files |
I have the following: QProcess *process = new QProcess(this); QString path = QDir::toNativeSeparators(QApplication::applicationPath); #if
I have a problem with QDir, I have this folder with lots of images,
When I do this: QDir myDir(/home/some/location); QStringList filesList = myDir.entryList(*); it is returning both
Qt's doc says that QDir::entryInfoList can accept multiple sorting conditions but how to do
I'm a little confused and would like to clear this up. //QDir()::rmdir is from
when I list entries via QDir::entryInfoList I'm getting two extra entries, one with dot
I'm setting my QFileSystemModel with following filters: QDir::Filters( Dirs|AllDirs|Files|Drives|NoDotAndDotDot|AllEntries ) In my proxy model,
What is the meaning of dot and dotdot when listing folders using QDir::entryList? It
It maybe a bug. Please read webclectic answer. If QFileInfo(filename) loss '/', QDir::absolutePath will

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.