QFile::copy()



  • 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.


  • Moderators

    @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.



  • @koahnig Thanks, it helped

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.