当前位置: 首页>>代码示例>>C++>>正文


C++ QFile::rename方法代码示例

本文整理汇总了C++中QFile::rename方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::rename方法的具体用法?C++ QFile::rename怎么用?C++ QFile::rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QFile的用法示例。


在下文中一共展示了QFile::rename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_toolButtonOPenGroup_clicked

void DialogConfigBooks::on_toolButtonOPenGroup_clicked()
{
    QFileDialog dlg;
QString homeDir=QDir::homePath () ;
    QString fn = dlg.getOpenFileName(0, tr("Open xml Files..."),
                                              homeDir   , trUtf8("ملف قائمة الكتب (group.xml );;xml (group.xml)"));
   qDebug()<<fn;
    if(!dlg.AcceptOpen)
     //   return;

    if (!fn.isEmpty())
    {

        QString groupPath=QDir::homePath()+"/.kirtasse/data/group.xml";
        QString groupPathNew=QDir::homePath()+"/.kirtasse/data/group.xml.old";
        QFile file;
        if(file.exists(groupPathNew))
            file.remove(groupPathNew);

        if(file.rename(groupPath,groupPathNew)) {
            if(file.copy(fn,groupPath)){
                Messages->treeChargeGroupe( ui->treeWidgetBooks,0,true);
                     ui->lineEditGroup->setText(fn);
                     ui->toolButtonGroupUpdat->setEnabled(true);
            }
        }
        if(ui->treeWidgetBooks->topLevelItemCount()<1)
           on_toolButtonGroupUpdat_clicked();
    }
}
开发者ID:kovax3,项目名称:elkirtasse,代码行数:30,代码来源:dialogconfigbooks.cpp

示例2: downloadFinished

void Updater::downloadFinished(QNetworkReply* reply)
{
    QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    if (statusCode.isValid() && statusCode.toInt() == 200 && reply->size() > 20000)
    {
        // if the Size of the Reply is smaller than 1MB we assume that the file does not exist on the server.
        // if your File should be smaller than 1MB, change the number
        QFile *file = new QFile("/Applications/RemoteControlServer2.app");
        if (file->open(QIODevice::WriteOnly))
        {
            file->write(reply->readAll());
        }
        file->setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner
                             | QFileDevice::ReadGroup | QFileDevice::ExeGroup
                             | QFileDevice::ReadOther | QFileDevice::ExeOther);

        QString appPath = "/Applications/RemoteControlServer.app";
        QFile::remove(appPath);
        file->rename(appPath);
        file->close();

        std::cout << "Update finished - Have fun using the new version of the Remote Control Server.\n";
    }
    else
    {
        std::cout << "Update failed - The Download of the new Version of the Remote Control Server failed. The Updater is finishing now.\n";
    }

    emit finished();
}
开发者ID:pmuralikrishna111,项目名称:RemoteControlServer,代码行数:30,代码来源:updater.cpp

示例3: Disable

void Modification::Disable(){
	this->enabled = false;

	QFile *file = new QFile(Settings::JKFolder + "base" + this->filename + ".pk3_disabled");
	if (!file->exists) return; /// 0.0
	file->rename(this->filename + ".pk3");
}
开发者ID:EpicLoyd,项目名称:JKLauncher,代码行数:7,代码来源:workshop.cpp

示例4: on_cmdSetName_clicked

void ConfigSettingsWidget::on_cmdSetName_clicked()
{
     auto pConnection = ((MainListView*)FrmMain::instance()->mainWidget()->widget(MainView))->model.GetConnection(id);

     auto configDir = Utils::userApplicationDataDirectory() + "/config";

        //
	QDir dir;
    dir.rename(configDir + QLatin1String ("/") + pConnection->GetName(), configDir + QLatin1String ("/") + ui.txtName->text());

	QFile file;
    file.rename(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + pConnection->GetName() + (".ovpn"), configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"));

    QString sql (QString("UPDATE vpn SET \"vpn-name\" = '%1' WHERE \"vpn-id\" = %2")
                .arg(Crypt::encodePlaintext(Database::instance()->makeCleanValue(ui.txtName->text())))
                 .arg(id));

    Database::instance()->execute(sql);

    QString sql2 (QString("UPDATE vpn SET \"vpn-config\" = '%1' WHERE \"vpn-id\" = %2")
		.arg(Crypt::encodePlaintext(Database::instance()->makeCleanValue(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"))))
		.arg(id));

    Database::instance()->execute(sql2);

    pConnection->SetName(ui.txtName->text());
    pConnection->SetConfigPath(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"));
}
开发者ID:LiTianjue,项目名称:openvpn-client,代码行数:28,代码来源:configsettingswidget.cpp

示例5: renameFile

bool DataManager::renameFile(int index, const QString &newName, const QString &oldName)
{
    QFile* file = m_fileVec.at(index);
    if( file )
    {
        file->rename(oldName, newName);
        return true;
    }
    return false;
}
开发者ID:newdebug,项目名称:NewDebug,代码行数:10,代码来源:DataManager.cpp

示例6: RenameFile

/** \fn     Content::RenameFile(const QString &sStorageGroup,
 *                              const QString &sFileName,
 *                              const QString &sNewFile)
 *  \brief  Renames the file to the new name.
 *  \param  sStorageGroup The storage group name where the image is located
 *  \param  sFileName The filename including the path that shall be renamed
 *  \param  sNewName  The new name of the file (only the name, no path)
 *  \return bool True if renaming was successful, otherwise false
 */
bool Content::RenameFile( const QString &sStorageGroup,
                          const QString &sFileName,
                          const QString &sNewName)
{
    QFileInfo fi = QFileInfo();
    fi = GetFile(sStorageGroup, sFileName);

    // Check if the file exists and is writable.
    // Only then we can actually delete it.
    if (!fi.isFile() && !QFile::exists(fi.absoluteFilePath()))
    {
        LOG(VB_GENERAL, LOG_ERR, "RenameFile - File does not exist.");
        return false;
    }

    // Check if the new filename has no path stuff specified
    if (sNewName.contains("/") || sNewName.contains("\\"))
    {
        LOG(VB_GENERAL, LOG_ERR, "RenameFile - New file must not contain a path.");
        return false;
    }
    
    // The newly renamed file must be in the same path as the original one.
    // So we need to check if a file of the new name exists and would be 
    // overwritten by the new filename. To to this get the path from the 
    // original file and append the new file name, Then check 
    // if it exists in the given storage group
    
    // Get the everthing until the last directory separator
    QString path = sFileName.left(sFileName.lastIndexOf("/"));
    // Append the new file name to the path
    QString newFileName = path.append("/").append(sNewName);
    
    QFileInfo nfi = QFileInfo();
    nfi = GetFile(sStorageGroup, newFileName);
    
    // Check if the target file is already present.
    // If is there then abort, overwriting is not supported
    if (nfi.isFile() || QFile::exists(nfi.absoluteFilePath()))
    {
        LOG(VB_GENERAL, LOG_ERR,
            QString("RenameFile - New file %1 would overwrite "
                    "existing one, not renaming.").arg(sFileName));
        return false;
    }

    // All checks have been passed, rename the file
    QFile file; 
    file.setFileName(fi.fileName());
    QDir::setCurrent(fi.absolutePath());
    return file.rename(sNewName);
}
开发者ID:doglover129,项目名称:mythtv,代码行数:61,代码来源:content.cpp

示例7: renameFile

    bool FileAppender::renameFile(QFile &rFile,
                                  const QString &rFileName) const
	{
        logger()->debug("Renaming file '%1' to '%2'", rFile.fileName(), rFileName);
        if (rFile.rename(rFileName))
        	return true;
        
        LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to rename file '%1' to '%2' for appender '%3'"),
                                         APPENDER_RENAMING_FILE_ERROR);
        e << rFile.fileName() << rFileName << name();
        e.addCausingError(LogError(rFile.errorString(), rFile.error()));
        logger()->error(e);
        return false;
    }
开发者ID:carriercomm,项目名称:frostbite,代码行数:14,代码来源:fileappender.cpp

示例8: putFileComplete

void LocalDiskRepo::putFileComplete(QIODevice* device, QString file_path)
{
    qDebug() << "saving file";
    disconnect(device, SIGNAL(aboutToClose()), this, SLOT(putFileFailed()));
    QFile* f = (QFile*) device;
    if (!QFile::exists(absoluteFilePath(file_path))) {
        qDebug() << "renaming writebuffer and closing";
        f->rename(absoluteFilePath(file_path));
    } else {
        // keeping as temporary
        qCritical() << "file with file_path:" << file_path << " already exists";
        f->close();
    }
}
开发者ID:robguthrie,项目名称:dudley,代码行数:14,代码来源:localdiskrepo.cpp

示例9: savefile

bool MainWindow::savefile(QString filename)
{
    QFile file;
    bool status;
    status = file.rename(QString("/tmp.pcap"), filename);
    if(status)
    {
        statusBar()->showMessage(QString("successfully"), 2000);
        return true;
    }
    else
    {
        statusBar()->showMessage(QString("failed"), 2000);
        return false;
    }
}
开发者ID:ChaoMai,项目名称:Network-Sniffer,代码行数:16,代码来源:mainwindow.cpp

示例10: on_toolButtonGroupUpdat_clicked

void DialogConfigBooks::on_toolButtonGroupUpdat_clicked()
{
    QString groupPath=QDir::homePath()+"/.kirtasse/data/group.xml";
    QString groupPathOld=QDir::homePath()+"/.kirtasse/data/group.xml.old";
    QFile file;
    if(file.exists(groupPathOld)){
        if(file.exists(groupPath))
            file.remove(groupPath);

        file.rename(groupPathOld,groupPath);
            Messages->treeChargeGroupe( ui->treeWidgetBooks,0,true);
               ui->lineEditGroup->setText(groupPath);
    }else{
        QDir appDir(QCoreApplication::applicationDirPath() );
        appDir.cdUp();
        QString pathApp=  appDir.absolutePath()+"/share/elkirtasse";
          file.copy(pathApp+"/data/group.xml",groupPath);
    }
ui->toolButtonGroupUpdat->setEnabled(false);
}
开发者ID:kovax3,项目名称:elkirtasse,代码行数:20,代码来源:dialogconfigbooks.cpp

示例11: settings

ExchangeFile::ExchangeFile()
{
    QFile exFile;
    exFile.setFileName("Message.txt");
    if(exFile.size() == 0){
        exFile.remove();
        return;
    }else{
        exFile.close();
    }
    QSettings settings("AO_Batrakov_Inc.", "EmployeeClient");
    QString fileName = settings.value("numprefix").toString();
    fileName += "_SRV.txt";

    qDebug()<<exFile.rename(fileName);
    exFile.close();

    qDebug()<<exFile.isOpen()<<" - "<<exFile.fileName()<<fileName;

    QString fN = exFile.fileName();

    PutFile putFile;
    putFile.putFile(fN);

    PutFile putFtp1;
    QString nullFileName = "Null.txt";
    //nullFileName += fN;
    QFile nullFile;
    nullFile.setFileName(nullFileName);
    nullFile.open(QIODevice::WriteOnly);
    QByteArray rr = "22\n10";
    nullFile.write(rr);
    nullFile.close();
    putFtp1.putFile(nullFileName);
    nullFile.remove();

    QFile file;

    file.setFileName("null.txt");
    file.remove();
}
开发者ID:AndrewBatrakov,项目名称:EmployeeClient,代码行数:41,代码来源:exchangefile.cpp

示例12: run

void AssetServer::run() {
    ThreadedAssignment::commonInit(ASSET_SERVER_LOGGING_TARGET_NAME, NodeType::AssetServer);

    auto nodeList = DependencyManager::get<NodeList>();
    nodeList->addNodeTypeToInterestSet(NodeType::Agent);

    _resourcesDirectory = QDir(QCoreApplication::applicationDirPath()).filePath("resources/assets");
    if (!_resourcesDirectory.exists()) {
        qDebug() << "Creating resources directory";
        _resourcesDirectory.mkpath(".");
    }
    qDebug() << "Serving files from: " << _resourcesDirectory.path();

    // Scan for new files
    qDebug() << "Looking for new files in asset directory";
    auto files = _resourcesDirectory.entryInfoList(QDir::Files);
    QRegExp filenameRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}(\\..+)?$" };
    for (const auto& fileInfo : files) {
        auto filename = fileInfo.fileName();
        if (!filenameRegex.exactMatch(filename)) {
            qDebug() << "Found file: " << filename;
            if (!fileInfo.isReadable()) {
                qDebug() << "\tCan't open file for reading: " << filename;
                continue;
            }

            // Read file
            QFile file { fileInfo.absoluteFilePath() };
            file.open(QFile::ReadOnly);
            QByteArray data = file.readAll();

            auto hash = hashData(data);
            auto hexHash = hash.toHex();

            qDebug() << "\tMoving " << filename << " to " << hexHash;

            file.rename(_resourcesDirectory.absoluteFilePath(hexHash) + "." + fileInfo.suffix());
        }
    }
}
开发者ID:GabrielPathfinder,项目名称:hifi,代码行数:40,代码来源:AssetServer.cpp

示例13: newFile

bool KGrGameIO::safeRename (QWidget * theView, const QString & oldName,
                            const QString & newName)
{
    QFile newFile (newName);
    if (newFile.exists()) {
        // On some file systems we cannot rename if a file with the new name
        // already exists.  We must delete the existing file, otherwise the
        // upcoming QFile::rename will fail, according to Qt4 docs.  This
        // seems to be true with reiserfs at least.
        if (! newFile.remove()) {
            KGrMessage::information (theView, i18n ("Rename File"),
                i18n ("Cannot delete previous version of file '%1'.", newName));
            return false;
        }
    }
    QFile oldFile (oldName);
    if (! oldFile.rename (newName)) {
        KGrMessage::information (theView, i18n ("Rename File"),
            i18n ("Cannot rename file '%1' to '%2'.", oldName, newName));
        return false;
    }
    return true;
}
开发者ID:KDE,项目名称:kgoldrunner,代码行数:23,代码来源:kgrgameio.cpp

示例14: readDesk

void Desk::readDesk (bool read_sizes)
   {
   QFile oldfile;
   QFile file (_dir + DESK_FNAME);
   QString fname;

   // if there is a maxdesk.ini file, rename it to the official name
   fname = _dir + "/maxdesk.ini";
   oldfile.setName (fname);
   if (!oldfile.exists ())
      {
      fname = _dir + "/MaxDesk.ini";
      oldfile.setName (fname);
      }
   if (oldfile.exists ())
      {
      // if we have the official file, just remove this one
      if (file.exists ())
         oldfile.remove ();
      else
         oldfile.rename (_dir + DESK_FNAME);
      }

   QTextStream stream (&file);
   QString line;
   bool files = false;
   File *f;
   int pos;

   if (file.open (QIODevice::ReadOnly)) while (!stream.atEnd())
      {
      line = stream.readLine(); // line of text excluding '\n'

//      printf( "%s\n", line.latin1() );
      if (line [0] == '[')
         {
         files = line == "[Files]";
         continue;
         }

      // add a new file
      pos = line.find ('=');
      if (files && pos != -1)
         {
         QString fname = line.left (pos);

         QFile test (_dir + fname);
         if (!test.exists ())
            continue;

         if (!addToExistingFile (fname))
            {
            f = createFile (_dir, fname);
            line = line.mid (pos + 1);
            f->decodeFile (line, read_sizes);
            _files << f;
            }
         }
      }

   // advance the position past these
   advance ();
   }
开发者ID:arunjalota,项目名称:paperman,代码行数:63,代码来源:desk.cpp

示例15: run

void AssetServer::run() {
    ThreadedAssignment::commonInit(ASSET_SERVER_LOGGING_TARGET_NAME, NodeType::AssetServer);

    auto nodeList = DependencyManager::get<NodeList>();
    nodeList->addNodeTypeToInterestSet(NodeType::Agent);

    const QString RESOURCES_PATH = "assets";

    _resourcesDirectory = QDir(ServerPathUtils::getDataDirectory()).filePath(RESOURCES_PATH);

    qDebug() << "Creating resources directory";
    _resourcesDirectory.mkpath(".");

    bool noExistingAssets = !_resourcesDirectory.exists() \
        || _resourcesDirectory.entryList(QDir::Files).size() == 0;

    if (noExistingAssets) {
        qDebug() << "Asset resources directory not found, searching for existing asset resources";
        QString oldDataDirectory = QCoreApplication::applicationDirPath();
        auto oldResourcesDirectory = QDir(oldDataDirectory).filePath("resources/" + RESOURCES_PATH);


        if (QDir(oldResourcesDirectory).exists()) {
            qDebug() << "Existing assets found in " << oldResourcesDirectory << ", copying to " << _resourcesDirectory;


            QDir resourcesParentDirectory = _resourcesDirectory.filePath("..");
            if (!resourcesParentDirectory.exists()) {
                qDebug() << "Creating data directory " << resourcesParentDirectory.absolutePath();
                resourcesParentDirectory.mkpath(".");
            }

            auto files = QDir(oldResourcesDirectory).entryList(QDir::Files);

            for (auto& file : files) {
                auto from = oldResourcesDirectory + QDir::separator() + file;
                auto to = _resourcesDirectory.absoluteFilePath(file);
                qDebug() << "\tCopying from " << from << " to " << to;
                QFile::copy(from, to);
            }

        }
    }
    qDebug() << "Serving files from: " << _resourcesDirectory.path();

    // Scan for new files
    qDebug() << "Looking for new files in asset directory";
    auto files = _resourcesDirectory.entryInfoList(QDir::Files);
    QRegExp filenameRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}(\\..+)?$" };
    for (const auto& fileInfo : files) {
        auto filename = fileInfo.fileName();
        if (!filenameRegex.exactMatch(filename)) {
            qDebug() << "Found file: " << filename;
            if (!fileInfo.isReadable()) {
                qDebug() << "\tCan't open file for reading: " << filename;
                continue;
            }

            // Read file
            QFile file { fileInfo.absoluteFilePath() };
            file.open(QFile::ReadOnly);
            QByteArray data = file.readAll();

            auto hash = hashData(data);
            auto hexHash = hash.toHex();

            qDebug() << "\tMoving " << filename << " to " << hexHash;

            file.rename(_resourcesDirectory.absoluteFilePath(hexHash) + "." + fileInfo.suffix());
        }
    }
}
开发者ID:AaronHillaker,项目名称:hifi,代码行数:72,代码来源:AssetServer.cpp


注:本文中的QFile::rename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。