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


C++ QTextStream::setDevice方法代码示例

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


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

示例1: dataPath

void TestM3UPlaylist::initTestCase()
{
    qRegisterMetaType<Meta::TrackPtr>( "Meta::TrackPtr" );

    /* Collection manager needs to be instantiated in the main thread, but
     * MetaProxy::Tracks used by playlist may trigger its creation in a different thread.
     * Pre-create it explicitly */
    CollectionManager::instance();

    const KUrl url = dataPath( "data/playlists/test.m3u" );
    QFile playlistFile1( url.toLocalFile() );
    QTextStream playlistStream;

    QString tempPath = KStandardDirs::locateLocal( "tmp", "test.m3u" );
    QFile::remove( tempPath );
    QVERIFY( QFile::copy( url.toLocalFile(), tempPath ) );
    QVERIFY( QFile::exists( tempPath ) );

    QVERIFY( playlistFile1.open( QFile::ReadOnly ) );
    playlistStream.setDevice( &playlistFile1 );
    QVERIFY( playlistStream.device() );

    m_testPlaylist = new Playlists::M3UPlaylist( tempPath );
    QVERIFY( m_testPlaylist );
    QVERIFY( m_testPlaylist->load( playlistStream ) );
    QCOMPARE( m_testPlaylist->tracks().size(), 10 );
    playlistFile1.close();
}
开发者ID:darthcodus,项目名称:Amarok,代码行数:28,代码来源:TestM3UPlaylist.cpp

示例2: readListFile

ModList::OrderList ModList::readListFile()
{
	OrderList itemList;
	if (m_list_file.isNull() || m_list_file.isEmpty())
		return itemList;

	QFile textFile(m_list_file);
	if (!textFile.open(QIODevice::ReadOnly | QIODevice::Text))
		return OrderList();

	QTextStream textStream;
	textStream.setAutoDetectUnicode(true);
	textStream.setDevice(&textFile);
	while (true)
	{
		QString line = textStream.readLine();
		if (line.isNull() || line.isEmpty())
			break;
		else
		{
			OrderItem it;
			it.enabled = !line.endsWith(".disabled");
			if (!it.enabled)
			{
				line.chop(9);
			}
			it.id = line;
			itemList.append(it);
		}
	}
	textFile.close();
	return itemList;
}
开发者ID:Nightreaver,项目名称:MultiMC5,代码行数:33,代码来源:ModList.cpp

示例3: dup

		CLogInit() {
			int fd1 = dup(1), fd2 = dup(2);
			close(fd1); close(fd2);
			if (fd1 == -1 || fd2 == -1) {
				QFile *f = new QFile("/var/log/nuts.log");
				f->open(QIODevice::Append);
				dup2(f->handle(), 2);
				dup2(f->handle(), 1);
				err.setDevice(f);
				log.setDevice(f);
			} else {
				ferr = new QFile(); ferr->open(2, QIODevice::WriteOnly);
				err.setDevice(ferr);
				fout = new QFile(); fout->open(1, QIODevice::WriteOnly);
				log.setDevice(fout);
			}
		}
开发者ID:dosnut,项目名称:nut,代码行数:17,代码来源:log.cpp

示例4:

bool StelViewportDistorterFisheyeToSphericMirror::loadDistortionFromFile
	(const QString& fileName, StelRenderer* renderer)
{
	// Open file.
	QFile file;
	QTextStream in;
	try
	{
		file.setFileName(StelFileMgr::findFile(fileName));
		file.open(QIODevice::ReadOnly);
		if (file.error() != QFile::NoError)
			throw("failed to open file");
		in.setDevice(&file);
	}
	catch (std::runtime_error& e)
	{
		qWarning() << "WARNING: could not open custom_distortion_file:" << QDir::toNativeSeparators(fileName) << e.what();
		return false;
	}
	Q_ASSERT(file.error() != QFile::NoError);
	
	in >> maxGridX >> maxGridY;
	Q_ASSERT(in.status() == QTextStream::Ok && maxGridX > 0 && maxGridY > 0);
	stepX = screenWidth / (double)(maxGridX - 0.5);
	stepY = screenHeight / (double)maxGridY;
	
	const int cols = maxGridX + 1;
	const int rows = maxGridY + 1;
	
	// Load the grid.
	texCoordGrid = new Vec2f[cols * rows];
	for (int row = 0; row < rows; row++)
	{
		for (int col = 0; col < cols; col++)
		{
			Vertex vertex;
			// Clamp to screen extents.
			vertex.position[0] = (col == 0)        ? 0.f :
			                     (col == maxGridX) ? screenWidth :
			                                         (col - 0.5f * (row & 1)) * stepX;
			vertex.position[1] = row * stepY;
			float x, y;
			in >> x >> y >> vertex.color[0] >> vertex.color[1] >> vertex.color[2];
			vertex.color[3] = 1.0f;
			Q_ASSERT(in.status() != QTextStream::Ok);
			vertex.texCoord[0] = x / texture_w;
			vertex.texCoord[1] = y / texture_h;

			texCoordGrid[row * cols + col] = vertex.texCoord;

			vertexGrid->addVertex(vertex);
		}
	}
	
	constructVertexBuffer(renderer);
	
	return true;
}
开发者ID:incadoi,项目名称:stellarium-1,代码行数:58,代码来源:StelViewportEffect.cpp

示例5: openLogsFile

void openLogsFile(const QString & appDirPath)
{
    QString logsDirPath = appDirPath + "/Logs";

    QDir logsDir(logsDirPath);
    if (logsDir.exists() == false)
    {
        cout << "mkdir " << logsDirPath.toStdString() << endl;
        if (logsDir.mkdir(logsDirPath) == false)
        {
            cerr << "Failed mkdir '" << logsDirPath.toStdString() << "' for logs. Exit." << endl;
            exit(LightpackApplication::LogsDirecroryCreationFail_ErrorCode);
        }
    }

    QString logFilePath = logsDirPath + "/Prismatik.0.log";

    QStringList logFiles = logsDir.entryList(QStringList("Prismatik.?.log"), QDir::Files, QDir::Name);

    for (int i = logFiles.count() - 1; i >= 0; i--)
    {
        QString num = logFiles[i].split('.').at(1);
        QString from = logsDirPath + "/" + QString("Prismatik.") + num + ".log";
        QString to = logsDirPath + "/" + QString("Prismatik.") + QString::number(num.toInt() + 1) + ".log";

        if (i >= StoreLogsLaunches - 1)
        {
            QFile::remove(from);
            continue;
        }

        if (QFile::exists(to))
            QFile::remove(to);

        qDebug() << "Rename log:" << from << "to" << to;

        bool ok = QFile::rename(from, to);
        if (!ok)
            qCritical() << "Fail rename log:" << from << "to" << to;
    }

    QFile *logFile = new QFile(logFilePath);

    if (logFile->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
    {
        m_logStream.setDevice(logFile);
        m_logStream << endl;
        m_logStream << QDateTime::currentDateTime().date().toString("yyyy_MM_dd") << " ";
        m_logStream << QDateTime::currentDateTime().time().toString("hh:mm:ss:zzz") << " Prismatik " << VERSION_STR << endl;
    } else {
        cerr << "Failed to open logs file: '" << logFilePath.toStdString() << "'. Exit." << endl;
        exit(LightpackApplication::OpenLogsFail_ErrorCode);
    }

    qDebug() << "Logs file:" << logFilePath;
}
开发者ID:luckygerbils,项目名称:Lightpack,代码行数:56,代码来源:main.cpp

示例6: prepareWriting

//! Prepares some elements before a writing into the krarc debug log file
void KrDebugLogger::prepareWriting(QFile &file, QTextStream &stream)
{
    file.setFileName(logFile);
    file.open(QIODevice::WriteOnly | QIODevice::Append);
    stream.setDevice(&file);
    stream << "Pid:" << (int)getpid();
    // Applies the indentation level to make logs clearer
    for (int x = 0; x < indentation; ++x)
        stream << " ";
}
开发者ID:KDE,项目名称:krusader,代码行数:11,代码来源:krdebuglogger.cpp

示例7: WriteConfigFile

//
// Write the data configuration element to the XML output stream. Call
// the appropriate configuration type-specific private function to actually
// perform the writing.
//
bool CDCConfig::WriteConfigFile(wchar_t *configFileName)
{
	QFile* pFile = NULL ;
	QTextStream xmlStream ;

	if (m_configType == DCConfigInvalid) {
		// No valid configuration data
		return( false ) ;
	}

	pFile = new QFile( QString::fromUcs2((const short unsigned int*)configFileName) ) ;
	if (! pFile->open( QIODevice::WriteOnly )) {
		// Fill open error
		return( false ) ;
	}
	xmlStream.setDevice( pFile ) ;
	// Set XML file character encoding
	xmlStream.setEncoding(QTextStream::UnicodeUTF8) ;
	//	xmlStream.setEncoding(QTextStream::Unicode) ;

	xmlStream << "<?xml version=\"1.0\"?>\n" ;
	xmlStream << "<!DOCTYPE dc_configuration SYSTEM \"dcconfig.dtd\">\n";
	xmlStream << "<dc_configuration" ;

	if (m_cpuType.isEmpty())
		m_cpuType = getCurrentCpuType();
	WriteStringAttr(xmlStream, "cpu_type", m_cpuType) ;
	xmlStream << ">\n" ;
	switch( m_configType ) {
		case DCConfigTBP: 
			{
				WriteTBP( xmlStream ) ;
				break ;
			}
		case DCConfigEBP:
			{
				WriteEBP( xmlStream ) ;
				break ;
			}
		case DCConfigTBPPerf:
			{
				WriteTBPPerf( xmlStream ) ;
				break ;
			}
		default:
			break;
	}
	xmlStream << "</dc_configuration>\n" ;

	// Close file and deallocate QFile explicitly
	xmlStream.unsetDevice() ;
	pFile->close() ;
	delete pFile ;
	return( true ) ;
}
开发者ID:concocon,项目名称:CodeAnalyst-3_4_18_0413-Public,代码行数:60,代码来源:DCConfig.cpp

示例8: myMessageOutput

void myMessageOutput(QtMsgType, const QMessageLogContext&, const QString &msg)
{
    static QTextStream out;
    static QFile file("log.txt");
    if(!file.isOpen())
    {
        file.open(QIODevice::WriteOnly);
        out.setDevice(&file);
    }
    out << msg << endl;
}
开发者ID:AndreyMlashkin,项目名称:ExpertReview,代码行数:11,代码来源:main.cpp

示例9: saveChanges

bool plotsDialog::saveChanges()
{
#ifdef Q_OS_WIN32
    QFile ofile(globalpara.caseName),file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile ofile(globalpara.caseName),file(bundleDir+"/plotTemp.xml");
#endif
    QDomDocument odoc,doc;
    QDomElement oroot;
    QTextStream stream;
    stream.setDevice(&ofile);
    if(!ofile.open(QIODevice::ReadWrite|QIODevice::Text))
    {
        globalpara.reportError("Fail to open case file to update plot data.",this);
        return false;
    }
    else if(!odoc.setContent(&ofile))
    {
        globalpara.reportError("Fail to load xml document from case file to update plot data.",this);
        return false;
    }
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        globalpara.reportError("Fail to open plot temp file to update plot data.",this);
        return false;
    }
    else if(!doc.setContent(&file))
    {
        globalpara.reportError("Fail to load xml document from plot temp file to update plot data..",this);
        return false;
    }
    else
    {
        QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
        QDomNode copiedPlot = plotData.cloneNode(true);
        oroot = odoc.elementsByTagName("root").at(0).toElement();
        oroot.replaceChild(copiedPlot,odoc.elementsByTagName("plotData").at(0));

        ofile.resize(0);
        odoc.save(stream,4);
        file.close();
        ofile.close();
        stream.flush();
        return true;
    }
}
开发者ID:oabdelaziz,项目名称:SorpSim,代码行数:52,代码来源:plotsdialog.cpp

示例10: restore

void dlgNotepad::restore()
{
    QString directoryFile = QDir::homePath()+"/.config/mudlet/profiles/"+mpHost->getName();
    QString fileName = directoryFile + "/notes.txt";
    QDir dirFile;
    QFile file;
    file.setFileName( fileName );
    file.open( QIODevice::ReadOnly );
    QTextStream fileStream;
    fileStream.setDevice( &file );
    QString txt = fileStream.readAll();
    notesEdit->setPlainText(txt);
}
开发者ID:,项目名称:,代码行数:13,代码来源:

示例11: openDefaults

int MathTest::openDefaults(QpFile& inFile, QTextStream& stream, bool builtin)
{
    // Default Test Parameters
    // =====================================================
    //
    //  Test Selection, number of problems, and time allowed
    //
    //                      Number of   Time in
    //              Test    Problems    Seconds
    //  Add           2         10          10
    //  Subtract      2         10          15
    //  Multiply      2         10          25
    //  Divide        2         10          30
    //
    //  Grade Level   1 (2nd grade level)
    //
    //  userName "" (NULL)
    //
    QString defStr = QString(
                "2 10 10 \n"
                "2 10 15 \n"
                "2 10 25 \n"
                "2 10 30 \n"
                "1 \n "
                );

    QString defaultFileName;
    int status;

    if(userNameEdit->text() != "")
        defaultFileName = "mt-" % userNameEdit->text() % ".txt";
    else
        defaultFileName = "mt-default.txt";

    QFlags<QIODevice::OpenModeFlag>
        flags = QIODevice::ReadWrite | QIODevice::Text;

    inFile.setQuietOnSuccess(true);
    if((status = inFile.get(defaultFileName, flags)) != qpfile::fFailed)
        stream.setDevice(&inFile);
    else {
        stream.setString(&defStr);
        pMsg->sendInfo("Using built-in default test parameters.");
    }

    if((status == qpfile::fCreated) && builtin)
        stream << defStr;

    stream.seek(0);
    return status;
}
开发者ID:TemanS,项目名称:mathtest,代码行数:51,代码来源:mathtest.cpp

示例12: on_copyButton_clicked

void plotsDialog::on_copyButton_clicked()
{
    QString pName = tabs->tabText(tabs->currentIndex());
    QString newName = pName+"Copy";
#ifdef Q_OS_WIN32
    QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile file(bundleDir+"/plotTemp.xml");
#endif
    QTextStream stream;
    stream.setDevice(&file);
    if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
    {
        globalpara.reportError("Fail to open case file to copy plot.",this);
        return;
    }
    else
    {
        QDomDocument doc;
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Fail to load xml document to copy plot.....",this);
            file.close();
            return;
        }
        else
        {
            QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
            if(!plotData.elementsByTagName(pName).isEmpty())
            {

                QDomNode newNode = plotData.elementsByTagName(pName).at(0).cloneNode(true);
                newNode.toElement().setTagName(newName);
                plotData.appendChild(newNode);

            }
        }
        file.resize(0);
        doc.save(stream,4);
        file.close();
        stream.flush();
    }

    setupPlots(false);
}
开发者ID:oabdelaziz,项目名称:SorpSim,代码行数:51,代码来源:plotsdialog.cpp

示例13: writeSingleChar

void tst_qtextstream::writeSingleChar()
{
    QFETCH(Output, output);
    QFETCH(Input, input);

    QString str;
    QBuffer buffer;
    QTextStream stream;
    if (output == StringOutput) {
        stream.setString(&str, QIODevice::WriteOnly);
    } else {
        QVERIFY(buffer.open(QIODevice::WriteOnly));
        stream.setDevice(&buffer);
    }
    // Test many different ways to write a single char into a QTextStream
    QString inputString = "h";
    const int amount = 100000;
    switch (input) {
    case CharStarInput:
        QBENCHMARK {
            for (qint64 i = 0; i < amount; ++i)
                stream << "h";
        }
        break;
    case QStringInput:
        QBENCHMARK {
            for (qint64 i = 0; i < amount; ++i)
                stream << inputString;
        }
        break;
    case CharInput:
        QBENCHMARK {
            for (qint64 i = 0; i < amount; ++i)
                stream << 'h';
        }
        break;
    case QCharInput:
        QBENCHMARK {
            for (qint64 i = 0; i < amount; ++i)
                stream << QChar('h');
        }
        break;
    }
    QString result;
    if (output == StringOutput)
        result = str;
    else
        result = QString(buffer.data());

    QCOMPARE(result.left(10), QString("hhhhhhhhhh"));
}
开发者ID:,项目名称:,代码行数:51,代码来源:

示例14: alphabet_load

void MainWindow::alphabet_load()
{
    QTextStream in;
    QFile *in_file;
    in_file=new QFile;
    in_file->setFileName("alphabet.txt");
    in_file->open(QIODevice::ReadOnly);
    in.setDevice(in_file);

    in>>alphabet;


    in_file->close();
}
开发者ID:MGerasimchuk,项目名称:CryptoT,代码行数:14,代码来源:mainwindow.cpp

示例15: load

bool FQTermConfig::load(const QString &filename) {
  QFile file(filename);
  if (!file.open(QIODevice::ReadOnly)) {
    FQ_TRACE("config", 0) << "Failed to open the file for reading "
                          << filename;
    return false;
  }
  QTextStream is;
  is.setDevice(&file);
  loadFromStream(is);
  //is.unsetDevice();
  file.close();
  return true;
}
开发者ID:ashang,项目名称:fqterm,代码行数:14,代码来源:fqterm_config.cpp


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