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. Rename desktop file icon issue

Rename desktop file icon issue

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 286 Views
  • 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #1

    Hi! I want to rename the shortcut for the some program. I have tried it both ways, but it fails (always returns false) and file is still with old name.

    Code:

    QDir myDir;
    myDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).replace("/", "\\"));
    qDebug() << myDir.rename("Test.lnk", "Test (1).lnk");
    
    QDir myDir;
    myDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).replace("/", "\\"));
    qDebug() << QFile::rename(myDir.path() + "\\Test.lnk", myDir.path() + "\\Test (1).lnk");
    

    I run a few test and it renames files in different locations, but not in QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).

    Any ideas how to rename the file in the desktop location? Thanks.

    1 Reply Last reply
    0
    • Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on last edited by
      #2

      I have fixed it by using Win API (MoveFile function):

      Code:

      QDir myDir;
      myDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).replace("/", "\\"));
      
      QString oldName = myDir.path() + "\\Test.lnk";
      QString newName = myDir.path() + "\\Test (1).lnk";
      bool renameRes = MoveFile(oldName.toStdWString().c_str(), newName.toStdWString().c_str());
      
       if (renameRes) {
            qDebug() << "File has been renamed!";
       } else {
            qDebug() << "Failed to rename the file!";
       }
      

      Now it works well. The issue is resolved.

      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