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. QFile::copy()

QFile::copy()

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k Views 2 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.
  • C Offline
    C Offline
    Corpse0327
    wrote on last edited by Corpse0327
    #1

    I am trying to make a program that makes some of the most common used features of Qt Creator easy. It is intended for UE4 users.

    // Save Qt dir to qtDir
    qtDir = ui->lineEditQtDir->text();
    
    if(qtDir.isEmpty()
            && QDir(qtDir).exists())
    {
        Warning("Set the directory for Qt please!");
        return;
    }
    
    QFile styleMonokai(":/Files/QCStyles/monokai.xml");
    QFile styleDusk(":/Files/QCStyles/dusk.xml");
    QFile styleTwilight(":/Files/QCStyles/twilight.xml");
    QFile styleVS2012_Intellisense(":/Files/QCStyles/vs2012_intellisense.xml");
    
    QString tempNewDir(qtDir + "/Tools/QtCreator/share/qtcreator/styles/");
    
    if(!QDir(tempNewDir).exists())
    {
        Warning("Dir doesn't exists!");
        return;
    }
    
    if(!(styleMonokai.exists()
            && styleDusk.exists()
            && styleTwilight.exists()
            && styleVS2012_Intellisense.exists())
            )
    {
        Warning("Style(s) doesn't exists!");
        return;
    }
    
    if(!(styleMonokai.copy(tempNewDir + styleMonokai.fileName())
         & styleDusk.copy(tempNewDir + styleDusk.fileName())
         & styleTwilight.copy(tempNewDir + styleTwilight.fileName())
         & styleVS2012_Intellisense.copy(tempNewDir + styleVS2012_Intellisense.fileName()))
            )
    {
        Warning("Copying style(s) failed!");
    }
    

    In the above code, copying fails, the output is "Copying style(s) failed!". I think i misuse copy function. How can i copy one file in a directory to another directory? I found lots of links about it, but it seems i failed to properly use copy function.

    It would be nice if someone gives an example.

    K 1 Reply Last reply
    0
    • C Corpse0327

      I am trying to make a program that makes some of the most common used features of Qt Creator easy. It is intended for UE4 users.

      // Save Qt dir to qtDir
      qtDir = ui->lineEditQtDir->text();
      
      if(qtDir.isEmpty()
              && QDir(qtDir).exists())
      {
          Warning("Set the directory for Qt please!");
          return;
      }
      
      QFile styleMonokai(":/Files/QCStyles/monokai.xml");
      QFile styleDusk(":/Files/QCStyles/dusk.xml");
      QFile styleTwilight(":/Files/QCStyles/twilight.xml");
      QFile styleVS2012_Intellisense(":/Files/QCStyles/vs2012_intellisense.xml");
      
      QString tempNewDir(qtDir + "/Tools/QtCreator/share/qtcreator/styles/");
      
      if(!QDir(tempNewDir).exists())
      {
          Warning("Dir doesn't exists!");
          return;
      }
      
      if(!(styleMonokai.exists()
              && styleDusk.exists()
              && styleTwilight.exists()
              && styleVS2012_Intellisense.exists())
              )
      {
          Warning("Style(s) doesn't exists!");
          return;
      }
      
      if(!(styleMonokai.copy(tempNewDir + styleMonokai.fileName())
           & styleDusk.copy(tempNewDir + styleDusk.fileName())
           & styleTwilight.copy(tempNewDir + styleTwilight.fileName())
           & styleVS2012_Intellisense.copy(tempNewDir + styleVS2012_Intellisense.fileName()))
              )
      {
          Warning("Copying style(s) failed!");
      }
      

      In the above code, copying fails, the output is "Copying style(s) failed!". I think i misuse copy function. How can i copy one file in a directory to another directory? I found lots of links about it, but it seems i failed to properly use copy function.

      It would be nice if someone gives an example.

      K Offline
      K Offline
      koahnig
      wrote on last edited by koahnig
      #2

      @Corpse0327
      You might want to change the single ampersand to double ampersands.
      Further you should check what fileName() actually returns in each case. IIRC the target folder shall exist already.
      Also if there is already a file with the same name you have to delete this first. The copy method does not overwrite existing files. That is especially during testing a trap.

      Vote the answer(s) that helped you to solve your issue(s)

      C 1 Reply Last reply
      0
      • K koahnig

        @Corpse0327
        You might want to change the single ampersand to double ampersands.
        Further you should check what fileName() actually returns in each case. IIRC the target folder shall exist already.
        Also if there is already a file with the same name you have to delete this first. The copy method does not overwrite existing files. That is especially during testing a trap.

        C Offline
        C Offline
        Corpse0327
        wrote on last edited by Corpse0327
        #3

        @koahnig Thanks, it helped

        The problem was that i used QFile::filename(). Instead of QFile i used a QString and the problem is solved

        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