Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Delete file correct defination in C++
Forum Updated to NodeBB v4.3 + New Features

Delete file correct defination in C++

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 1.4k 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.
  • H Offline
    H Offline
    halil sogut68
    wrote on last edited by halil sogut68
    #1

    Hi,

    How to write correct defination of delete picture from default system picture .Here is below my code in C++ :

    void deleteFile()
    {

        QString parameter ="/storage/sdcard0/Pictures/{CB6942CE-8FDE-B00F-A07E-832ECAE05AF4}_1.jpg"
       // QString parameter ="file:///storage/sdcard0/Pictures/{CB6942CE-8FDE-B00F-A07E-832ECAE05AF4}_1.jpg"
    
         bool state=QFile::remove(parameter);
    
         if(state==true)
         {
             qDebug() << "delete successful";
         }
         else
         {
             qDebug() << "delete unsuccessful";
         }
    

    }

    Both of them parameter paths I've tried but ppplication output is like below:

    D/OfflineTests( 4216): (null):0 ((null)): delete unsuccessful

    How can I write correct delete code ?

    Thanks

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!
      Are you sure the file you want to delete actually exists? The following works for me:

      void MainForm::on_pushButton_clicked()
      {
          const QString fileName = QString("%1/myfile.txt").arg( QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) );
          ui->pushButton->setText( QFile::remove(fileName) ? ":-)" : ":-(" );
      }
      
      1 Reply Last reply
      0
      • H Offline
        H Offline
        halil sogut68
        wrote on last edited by
        #3

        Thanks dolved problem

        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