void MainWindow::DefaultPathExistCheck() { QString path = "configure.conf"; QFile* defaultPathFile = new QFile(path); if(defaultPathFile->exists()) { if (defaultPathFile->open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(defaultPathFile); while(!in.atEnd()) { _defaultOutputPath = in.readLine(); ui->_leDefaultDirPath->setText(_defaultOutputPath); } } } else { defaultPathFile->setFileName(path); } defaultPathFile->close(); }
void DefMgr::loadChipdefs() { m_chipdefs.clear(); static const QString defFileLocations[] = { ":/definitions/chipdefs", "./shupito_chipdefs.txt", Utils::storageLocation(Utils::DataLocation) + "/shupito_chipdefs.txt", }; QFile file; for(quint8 i = 0; i < sizeof(defFileLocations)/sizeof(QString); ++i) { file.setFileName(defFileLocations[i]); if(!file.open(QIODevice::ReadOnly)) continue; QTextStream stream(&file); parseChipdefs(stream); file.close(); } }
int KIPC::getProcessId(const QString &kludgetId) { int pid = 0; QString pidfile = getPIDFile(kludgetId); if (QFile::exists(pidfile)) { QFile file; file.setFileName(pidfile); if (file.open(QIODevice::ReadOnly)) { QString text = file.readAll(); file.close(); pid = text.toInt(); } } // qDebug(">>%s %d", qPrintable(kludgetId), pid); if (!checkProcess(pid)) return 0; return pid; }
QStringList Backend::languages() { QStringList _languages; QString code, desc, line; QFile mFile; mFile.setFileName("/usr/local/share/pc-sysinstall/conf/avail-langs"); if ( ! mFile.open(QIODevice::ReadOnly | QIODevice::Text)) return QStringList(); // Read in the meta-file for categories QTextStream in(&mFile); in.setCodec("UTF-8"); while ( !in.atEnd() ) { line = in.readLine(); code = line; code.truncate(line.indexOf(" ")); desc = line.remove(0, line.indexOf(" ")); _languages.append(desc.simplified() + " - (" + code.simplified() + ")"); } mFile.close(); return _languages; }
bool TestManager::readStudentDbFromFile() { QFile file; quint32 magic; quint16 streamVersion; StudentDb newStudentDb(this); file.setFileName(testsDir + "/" + studentDbFileName); if(!file.exists()) { qDebug() << "ERROR: File " << (testsDir + "/" + studentDbFileName) << " no exist."; return false; } if(!file.open(QIODevice::ReadOnly)) { qDebug() << "ERROR: Cannot open file for reading: " << file.errorString(); return false; } QDataStream in(&file); in >> magic >> streamVersion; if(magic != magicNumber) { qDebug() << "ERROR: File is not recognized by this application"; return false; } else if(streamVersion > in.version()) { qDebug() << "ERROR: File is from a more recent version of the application"; return false; } in >> newStudentDb; *students = newStudentDb; return true; }
/*! * \brief JsonParser::addObject * Dodaje obiekt do pliku json * \param type typ obiektu * \param speed prędkość obiektu * \param model model tabeli ze wskazanymi punktami */ void JsonParser::addObject(QString type, double speed, QStandardItemModel *model) { QJsonValue type_ = type; QJsonObject object; object.insert("TypeObject", type_); object.insert("Speed", speed); QJsonArray array; QJsonObject point; QJsonValue value; for (int i = 0; i <model->rowCount(); i++) { value = model->takeItem(i,0)->data(Qt::DisplayRole).toDouble(); point.insert("CoordX", value); value = model->takeItem(i,1)->data(Qt::DisplayRole).toDouble(); point.insert("CoordY", value); array.insert(i,point); } value = array; object.insert("Points", value); objects.push_back(object); QJsonDocument d; QJsonObject obj; obj.insert("Objects", static_cast<QJsonValue>(objects)); d.setObject(obj); d.toJson(); QFile file; file.setFileName(fileName); file.open(QIODevice::WriteOnly | QIODevice::Text); file.write(d.toJson()); file.close(); }
int TestMonitor::loadJsonObject(QString &fileName,QJsonObject &jsonObj ) { pthread_mutex_lock(&conn_mutex); QFile file; QString sampleDir = "../../doc/json_sample/"; sampleDir = "d:\\phonelin\\doc\\json_sample\\"; #if __linux__ sampleDir = "/home/hamigua/phonelin/doc/json_sample/"; #endif file.setFileName(sampleDir + fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { DEBUG_INFO << "Failed to open json sameple file:" + sampleDir + fileName; pthread_mutex_unlock(&conn_mutex); return PL_RET_FAIL; } QString data = file.readAll(); file.close(); QJsonDocument sd = QJsonDocument::fromJson(data.toUtf8()); if (!sd.isObject() || sd.isNull() || sd.isEmpty()) { DEBUG_INFO << "Failed to open json sameple file:" + fileName; pthread_mutex_unlock(&conn_mutex); return PL_RET_FAIL; } jsonObj = sd.object(); pthread_mutex_unlock(&conn_mutex); return PL_RET_OK; }
void TsunamiEvacModel::on_actionLoad_cost_grid_triggered() { QString fileName; fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::homePath(), tr("Image Files (*.csv)")); QList<QStringList> myMat; QFile file; file.setFileName(fileName); if(file.open(QIODevice::ReadOnly)) setStatus("File opened"); else setStatus("Could not open file"); while (!file.atEnd()){ QByteArray line = file.readLine(); QStringList temp; for(int i = 0; i < line.split(',').size(); i++) temp.append(line.split(',').at(i)); myMat.append(temp); } QString temp; delete myGrid; myGrid = new Grid(myMat.size(),myMat.at(1).size(),this); for(int i = 0; i < myMat.size(); i++){ for(int j = 0; j < myMat.at(i).size(); j++){ myGrid->setValue(i,j,myMat.at(i).at(j).toInt()); temp.append(myMat.at(i).at(j)); temp.append(" "); } temp.append("\n"); } ui->textBrowser->append(temp); }
//metodos del menu archivo void MainWindow::Abrir(){ //QString nombreArchivo; nombreArchivo_ = QFileDialog::getOpenFileName(this, tr("Abrir archivo de video"), "", tr("Archivo de video (*.mpeg *.avi *.wmv *.mp4 *.mov *.flv *.mp3 *.mpg)") ); if (nombreArchivo_ != "") { //Intentamos abrir el archivo QFile archivo; archivo.setFileName(nombreArchivo_); if (archivo.open(QFile::ReadOnly)) { mediaPlayer_->setMedia(QUrl::fromLocalFile(nombreArchivo_)); mediaPlayer_->play(); //mediaPlayer_->setVideoOutput(videoWidget_); playlist_->addMedia(QUrl::fromLocalFile(nombreArchivo_)); archivo.close(); Recientes_crear(nombreArchivo_); } } }
bool FileManager::open( QString path, QList<TrackModel*>* const trackModels, CategoryData* const categoryData, ImageData* const imageData ) { trackModels->clear(); QString jsonFromFile; QFile file; file.setFileName( path ); file.open( QIODevice::ReadOnly | QIODevice::Text ); jsonFromFile = file.readAll(); file.close(); // Get jsonObject out of jsonDoc QJsonDocument jsonDoc = QJsonDocument::fromJson( jsonFromFile.toUtf8() ); QJsonObject jsonObject = jsonDoc.object(); // Parse track data QJsonArray tracksArray = jsonObject.value("tracks").toArray(); for ( int i = 0; i < tracksArray.size(); i++ ) { QJsonObject trackObj = tracksArray.at(i).toObject(); TrackModel* trackModel = new TrackModel( trackObj ); trackModels->append( trackModel ); } // Parse category data if ( jsonObject.contains("categoryPath") ) { QString categoryPath = jsonObject.value("categoryPath").toString(""); FileManager::import( categoryPath, categoryData, imageData ); qDebug() << "Loaded category data from" << categoryPath; } else qDebug() << "No category data found..."; return trackModels->size() > 0; }
bool NokiaScreen::okToUpdate() { QString path = "/sys/devices/platform/omapfb/panel/backlight_level"; QString strvalue; int value; QFile brightness; if (QFileInfo(path).exists() ) { brightness.setFileName(path); } if( !brightness.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning()<<"brightness File not opened"; } else { QTextStream in(&brightness); in >> strvalue; brightness.close(); } if (strvalue.toInt() > 1 ) return true; else return false; }
QStringList StoragePoolControlThread::createStoragePool() { QStringList result; QString path = args.first(); QByteArray xmlData; QFile f; f.setFileName(path); if ( !f.open(QIODevice::ReadOnly) ) { emit errorMsg( QString("File \"%1\"\nnot opened.").arg(path) ); return result; }; xmlData = f.readAll(); f.close(); // flags: extra flags; not used yet, so callers should always pass 0 unsigned int flags = 0; virStoragePoolPtr storagePool = virStoragePoolCreateXML(currWorkConnect, xmlData.data(), flags); if ( storagePool==NULL ) { sendConnErrors(); return result; }; result.append(QString("'<b>%1</b>' StoragePool from\n\"%2\"\nis created.").arg(virStoragePoolGetName(storagePool)).arg(path)); virStoragePoolFree(storagePool); return result; }
PgnGame PgnGameIterator::next(bool* ok, int depth) { Q_ASSERT(hasNext()); int newDbIndex = m_dlg->databaseIndexFromGame(m_gameIndex); Q_ASSERT(newDbIndex != -1); if (newDbIndex != m_dbIndex) { m_dbIndex = newDbIndex; m_file.close(); const PgnDatabase* db = m_dlg->m_dbManager->databases().at(m_dbIndex); if (db->status() == PgnDatabase::Ok) { m_file.setFileName(db->fileName()); if (m_file.open(QIODevice::ReadOnly | QIODevice::Text)) m_in.setDevice(&m_file); else m_in.setDevice(nullptr); } } PgnGame game; if (!m_file.isOpen()) { *ok = false; m_gameIndex++; return game; } const PgnGameEntry* entry = m_dlg->m_pgnGameEntryModel->entryAt(m_gameIndex++); *ok = m_in.seek(entry->pos(), entry->lineNumber()) && game.read(m_in, depth); return game; }
bool codeEditor::open(QString name) { QFile file; QFileInfo fileInfo; file.setFileName(name); fileInfo.setFile(file); if(file.open(QIODevice::ReadWrite|QIODevice::Text)) { if(!read(&file)) return false; file_path=name; name=fileInfo.suffix(); if(name=="cpp"||name=="c") setLexer(new QsciLexerCPP); else if(name=="pas") setLexer(new QsciLexerPascal); return true; } return false; }
void MainWindow::saveShowData() { QString path="./"; QString fileName=QFileDialog::getSaveFileName(this, tr("Save Files(*.txt)"), path, tr("txt files(*.txt)")); if(fileName.isNull()) { QMessageBox::warning(this,tr("File Name Error!"),tr("file name cann't be null!"),QMessageBox::Ok); } else { QFile saveFile; saveFile.setFileName(fileName); if(saveFile.open(QIODevice::ReadWrite|QFile::Text)) { QTextStream saveFileStream(&saveFile); saveFileStream<<ui->reciveData->toPlainText(); saveFileStream.atEnd(); saveFile.close(); } } }
void Setting::readTxt() { QFile *file = new QFile; file->setFileName(QDir::currentPath()+"\\set.txt"); file->open(QIODevice::ReadOnly); QTextStream in(file); info = in.readAll(); file->close(); if(info.contains("日")) ui->sun->setChecked(true); if(info.contains("一")) ui->mon->setChecked(true); if(info.contains("二")) ui->tus->setChecked(true); if(info.contains("三")) ui->wen->setChecked(true); if(info.contains("四")) ui->thr->setChecked(true); if(info.contains("五")) ui->fri->setChecked(true); if(info.contains("六")) ui->sat->setChecked(true); if(info.split(";").at(1)=="0") ui->Enable->setChecked(true); QTime t1 = QTime::fromString(info.split(";").at(2),"hh,mm"); QTime t2 = QTime::fromString(info.split(";").at(3),"hh,mm"); ui->chosen->setTime(t1); ui->Else->setTime(t2); }
LONG WINAPI exceptionFilter(LPEXCEPTION_POINTERS info) { if (g_output == NULL) { g_output = (char*) malloc(BUFFER_MAX); } struct output_buffer ob; output_init(&ob, g_output, BUFFER_MAX); if (!SymInitialize(GetCurrentProcess(), 0, TRUE)) { output_print(&ob,"Failed to init symbol context\n"); } else { bfd_init(); struct bfd_set *set = (bfd_set*)calloc(1,sizeof(*set)); _backtrace(&ob , set , 128 , info->ContextRecord); release_set(set); SymCleanup(GetCurrentProcess()); } // Dump a stack trace to a file. QFile stackTraceFile; stackTraceFile.setFileName(QString("%1/openmodelica.stacktrace.%2").arg(OpenModelica::tempDirectory()).arg(Helper::OMCServerName)); if (stackTraceFile.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream out(&stackTraceFile); out.setCodec(Helper::utf8.toStdString().data()); out.setGenerateByteOrderMark(false); out << g_output; out.flush(); stackTraceFile.close(); } CrashReportDialog *pCrashReportDialog = new CrashReportDialog; pCrashReportDialog->exec(); exit(1); }
bool Map::saveMap() { QFile file; for(int i = 0; i < mapImform.size(); i++) { file.setFileName(mapImform[i].filePath); if(!file.open(QIODevice::WriteOnly)) { QMessageBox::warning(NULL,tr("Map editor"), tr("failed to save file")); return false; } QDataStream out(&file); out.setVersion(QDataStream::Qt_4_8); out << map_MagicNum; quint32 totalColumn = map[i].size(); quint32 totalRow = map[i][0].size(); out << totalRow; out << totalColumn; for(quint32 rowIndex = 0; rowIndex < totalRow; rowIndex++) { for(quint32 columnIndex = 0; columnIndex < totalColumn; totalColumn++) { out << rowIndex << columnIndex; out << map[i][rowIndex][columnIndex].id; out << map[i][rowIndex][columnIndex].status; } } } return true; }
bool QResourceStream::open(const char* path) { if(this->size != 0) { this->size = 0; this->pos = 0; free(dat); } static QFile file; file.setFileName(path); if(!file.open(QIODevice::ReadOnly)) return false; this->size = file.size(); dat = malloc(file.size()); if(dat == NULL) return false; if(file.read((char*) dat, file.size() + 1) == -1) return false; file.close(); return true; }
void MainWindow::getcpu() { QString tempStr; //读取文件信息字符串 QFile tempFile; //用于打开系统文件 int pos; //读取文件的位置 tempFile.setFileName("/proc/cpuinfo"); //打开CPU信息文件 if ( !tempFile.open(QIODevice::ReadOnly) ) { QMessageBox::warning(this, tr("warning"), tr("The cpuinfo file can not open!"), QMessageBox::Yes); return; } for(int i=0;i<10;i++) { tempStr = tempFile.readLine(); pos = tempStr.indexOf("model name"); if (pos != -1) { pos += 13; //跳过前面的"model name:"所占用的字符 QString *cpu_name = new QString( tempStr.mid(pos, tempStr.length()-13) ); fg5=cpu_name->contains("i5"); fg7=cpu_name->contains("i7"); } } }
void DEBUGLOGVIEWERWIDGET_C::LoadDebugLog(void) { QFileInfo FileInfo; QFile File; QString Data; /* Make sure there is a pathname. */ if (m_Pathname.isEmpty()==0) { /* Open the debug log file. */ File.setFileName(m_Pathname); if (File.open(QFile::ReadOnly)==true) { /* Read the debug log file. */ Data=File.readAll(); File.close(); if (Data.isEmpty()==0) { /* Populate the text edit with the contents of the debug log file. */ /** \todo Save scrollbar position and then after new data is set, restore the scrollbar position. **/ m_pTextEdit->setPlainText((Data)); /* Get and save the "last modified" date/time. */ FileInfo.setFile(File); m_LastModifiedDateTime=FileInfo.lastModified(); /* Disable the "Refresh" button. */ m_pButtonBox->button(QDialogButtonBox::Apply)->setEnabled(false); } } } return; }
//! [2] void QueryMainWindow::evaluate(const QString &str) { QFile sourceDocument; sourceDocument.setFileName(":/files/cookbook.xml"); sourceDocument.open(QIODevice::ReadOnly); QByteArray outArray; QBuffer buffer(&outArray); buffer.open(QIODevice::ReadWrite); QXmlQuery query; query.bindVariable("inputDocument", &sourceDocument); query.setQuery(str); if (!query.isValid()) return; QXmlFormatter formatter(query, &buffer); if (!query.evaluateTo(&formatter)) return; buffer.close(); findChild<QTextEdit*>("outputTextEdit")->setPlainText(QString::fromUtf8(outArray.constData())); }
void File::clear(QString target) { QDir dir(target); QFile file; if (dir.exists()) { QFileInfoList l = dir.entryInfoList(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); QFileInfo fi; foreach (fi, l) { if (fi.isDir()) { clear(fi.absoluteFilePath()); } else if (fi.isFile()) { file.setFileName(fi.absoluteFilePath()); if (!file.remove()) { qDebug("remove error"); } qDebug() << "remove" << fi.absoluteFilePath(); } } dir.cdUp(); if (!dir.rmdir(target)) { qDebug("rmdir error"); } qDebug() << "rmdir" << target; }
void UIImageOverview::deleteFile(void) { QFile f; QString filename; QString uri; QString cacheFile; filename = ui->listWidget->currentItem()->text(); if (filename != "") { f.setFileName(filename); if (f.exists()) { f.remove(); ui->listWidget->takeItem(ui->listWidget->currentRow()); } if (getUrlOfFilename(filename, &uri)) blackList->add(uri); } cacheFile = tnt->getCacheFile(filename); emit removeFiles(QStringList(cacheFile)); }
void loadBanList() { QString banlist; g_pApp->getLocalKvircDirectory(banlist, KviApplication::ConfigPlugins); banlist += g_pBanListFilename; QFile file; file.setFileName(banlist); if(!file.open(QIODevice::ReadOnly)) return; QTextStream stream(&file); g_pBanList->clear(); int i = 0; int num = stream.readLine().toInt(); while((!stream.atEnd()) && (i < num)) { QString * tmp = new QString(stream.readLine()); g_pBanList->append(tmp); i++; } file.close(); }
void WSettings::checkConfigFile() { //default config file "~/.WifiAssist/config.ini" //check is path exists QDir dir; QString config_path = dir.homePath()+"/.WifiAssist"; QString filename = config_path+"/config.ini"; dir.setPath(config_path); //if not exist,mkdir and Then set default config file. if(!dir.exists()) { dir.mkdir(config_path); } QFile file; file.setFileName(filename); if(!file.exists()) { m_settings = new QSettings(filename,QSettings::IniFormat); setDefaultConfig(); } else m_settings = new QSettings(filename,QSettings::IniFormat); }
QStringList inihandlerclass::stringlistfromini(const QString &inistring) { QFile f; f.setFileName(QApplication::applicationDirPath() + "/network/" + file); if (!f.open(QIODevice::ReadOnly)) { myDebug() << QObject::tr("the file network/wormnet.net is missing!"); } QTextStream ts(&f); while (ts.readLine() != inistring && !ts.atEnd()) ; if (ts.atEnd()) { myDebug() << QObject::tr("The file network/wormnet.net file is corrupt!") << inistring << QObject::tr(" can not be found, but is important."); return QStringList(""); } QStringList sl; QString s(ts.readLine()); while (!s.startsWith("[") && !ts.atEnd()) { if(!s.startsWith("//") && s!=""){ sl << s; } s = ts.readLine(); } return sl; }
// Write stack frames as task file for displaying it in the build issues pane. void StackHandler::saveTaskFile() { QFile file; QFileDialog fileDialog(Core::ICore::dialogParent()); fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.selectFile(QDir::currentPath() + "/stack.tasks"); while (!file.isOpen()) { if (fileDialog.exec() != QDialog::Accepted) return; const QString fileName = fileDialog.selectedFiles().constFirst(); file.setFileName(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { QString msg = tr("Cannot open \"%1\": %2") .arg(QDir::toNativeSeparators(fileName), file.errorString()); Core::AsynchronousMessageBox::warning(tr("Cannot Open Task File"), msg); } } QTextStream str(&file); for (const StackFrame &frame : frames()) { if (frame.isUsable()) str << frame.file << '\t' << frame.line << "\tstack\tFrame #" << frame.level << '\n'; } }
/*! Remove the destination directory for the sandboxed package and everything below it. Use this method with care. */ void SandboxInstallJob::removeDestination() const { QDir destDir( destination ); if ( !destDir.exists() ) { qWarning( "Request to remove non-existent directory %s", qPrintable( destination )); return; } QString cmd( "rm -Rf " ); cmd += destination; Q_ASSERT( !destination.isEmpty() && destination != "/" ); qLog(Package) << "Removing destination by executing:" << cmd; ScriptRunner::runScript( cmd ); QDir dir( Qtopia::packagePath() ); if ( dir.cd("tmp") ) { QFileInfoList fileList= dir.entryInfoList( QDir::Files ); QFile f; foreach( QFileInfo fi, fileList ) { f.setFileName( fi.absoluteFilePath() ); f.remove(); }
void WSettings::checkInterfaceListFile() { //default config file "~/.WifiAssist/config.ini" //check is path exists QDir dir; QString config_path = dir.homePath()+"/.WifiAssist"; dir.setPath(config_path); //if not exist,mkdir and Then set default config file. if(!dir.exists()) { dir.mkdir(config_path); } //run net.sh to get interface list QString interface_list_filename = config_path+"/interface.list"; QFile file; file.setFileName(interface_list_filename); if(!file.exists()) { QStringList args = QStringList() << QCoreApplication::applicationDirPath()+"/bin/net.sh"; QProcess qp; if(!qp.startDetached("bash",args)) { QMessageBox::about(NULL,"Warning!","Can't Get Interface List"); } QElapsedTimer t; t.start(); while(t.elapsed()<2000) QCoreApplication::processEvents(); } }