本文整理汇总了C++中QFile::readBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::readBlock方法的具体用法?C++ QFile::readBlock怎么用?C++ QFile::readBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::readBlock方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
void ZGui::load ( const QString fileName, bool AutoCodec )
{
toLog("load ("+fileName+")");
QFile file ( fileName );
if ( file.open ( IO_ReadWrite ) )//IO_ReadOnly ) )
{
//Block update
edit->blockSignals(true);
edit->setAutoUpdate(false);
//Set def editor
edit->clear();
edit->setText("");
//Detect codec
if ( AutoCodec )
{
//Reset all checked
for (int i=0; i<CODEC_COUNT;i++)
CodeMenu->setItemChecked(i,false);
//Read data for detect
char data[10000];
int size = file.readBlock(data, sizeof(data));
file.reset();
textCode = detectCodec(data, size);
//Check codec
CodeMenu->setItemChecked(textCode, true);
}
toLog("\tload text");
//Load file
char data[ file.size() ];
file.readBlock(data, sizeof(data));
QTextCodec* codec = codecByLocalId(textCode);
toLog("\tset text");
edit->setText( codec->toUnicode( data ) );
toLog("\tclose file");
file.close();
//Unblock update
edit->blockSignals(false);
edit->setAutoUpdate(true);
#ifdef MDI
setMainWidgetTitle(sFileName);
buildDlgMenu();
#endif
toLog("end load");
}
}
示例2: extractLibrary
// ---------------------------------------------------------------
int PackageDialog::extractLibrary(QFile& PkgFile, Q_UINT32 Count)
{
char *p = (char*)malloc(Count);
PkgFile.readBlock(p, Count);
QByteArray Content = qUncompress((unsigned char*)p, Count);
free(p);
p = Content.data();
QFile File(QucsSettings.QucsHomeDir.absPath() +
QDir::convertSeparators("/user_lib/") + QString(p));
if(File.exists()) {
MsgText->append(tr("ERROR: User library \"%1\" already exists!").arg(QString(p)));
return -1;
}
if(!File.open(QIODevice::WriteOnly)) {
MsgText->append(tr("ERROR: Cannot create library \"%1\"!").arg(QString(p)));
return -1;
}
File.writeBlock(p+strlen(p)+1, Content.size()-strlen(p)-1);
File.close();
MsgText->append(tr("Create library \"%1\"").arg(QString(p)));
return 1;
}
示例3: extractFile
// ---------------------------------------------------------------
int PackageDialog::extractFile(QFile& PkgFile, Q_UINT32 Count, QDir& currDir)
{
char *p = (char*)malloc(Count);
PkgFile.readBlock(p, Count);
QByteArray Content = qUncompress((unsigned char*)p, Count);
free(p);
p = Content.data();
QFile File(currDir.absFilePath(QString(p)));
if(!File.open(QIODevice::WriteOnly)) {
MsgText->append(tr("ERROR: Cannot create file \"%1\"!").arg(QString(p)));
return -1;
}
File.writeBlock(p+strlen(p)+1, Content.size()-strlen(p)-1);
File.close();
MsgText->append(tr("Create file \"%1\"").arg(QString(p)));
return 1;
}
示例4: extractDirectory
// ---------------------------------------------------------------
int PackageDialog::extractDirectory(QFile& PkgFile, Q_UINT32 Count, QDir& currDir)
{
char *p = (char*)malloc(Count);
PkgFile.readBlock(p, Count);
if(currDir.cd(QString(p))) { // directory exists ?
MsgText->append(tr("ERROR: Project directory \"%1\" already exists!").arg(QString(p)));
return -1;
}
if(!currDir.mkdir(QString(p))) {
MsgText->append(tr("ERROR: Cannot create directory \"%1\"!").arg(QString(p)));
return -2;
}
currDir.cd(QString(p));
MsgText->append(tr("Create and enter directory \"%1\"").arg(currDir.absPath()));
free(p);
return 1;
}
示例5: detectFileCodec
bool UtilsCode::detectFileCodec()
{
QFile file ( mFile );
if ( file.open ( IO_ReadWrite ) )
{
//cout<<"===== file open ok ====="<<endl;
char data[10000];
int size = file.readBlock(data, sizeof(data));
file.reset();
int id = detectCodec(data, size);
//cout<<"########## code id is "<<id<<" ########"<<endl;
mTextCodec = codecByLocalId(id);
file.close();
return true;
}
return false;
}
示例6: insertFile
int PackageDialog::insertFile(const QString& FileName, QFile& File,
QDataStream& Stream)
{
QByteArray FileContent;
if(!File.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Error"),
tr("Cannot open \"%1\"!").arg(FileName));
return -1;
}
Q_ULONG Count = File.size();
char *p = (char*)malloc(Count+FileName.length()+2);
strcpy(p, FileName.latin1());
File.readBlock(p+FileName.length()+1, Count);
File.close();
Count += FileName.length()+1;
FileContent = qCompress((unsigned char*)p, Count);
free(p);
Stream.writeBytes(FileContent.data(), FileContent.size());
return 0;
}
示例7: generatePage
//.........这里部分代码省略.........
copyFile(bibFile,destFile);
tempFiles.append(new QCString(destFile));
}
}
else if (!fi.exists())
{
err("bib file %s not found!\n",bibFile.data());
}
bibdata = citeDataList.next();
}
}
QCString oldDir = QDir::currentDirPath().utf8();
QDir::setCurrent(outputDir);
// 5. run bib2xhtml perl script on the generated file which will insert the
// bibliography in citelist.doc
portable_system("perl","\""+bib2xhtmlFile+"\" "+getListOfBibFiles(" ",FALSE)+" \""+
citeListFile+"\"");
QDir::setCurrent(oldDir);
// 6. read back the file
f.setName(citeListFile);
if (!f.open(IO_ReadOnly))
{
err("could not open file %s/citelist.doc for reading\n",outputDir.data());
}
bool insideBib=FALSE;
QCString doc;
QFileInfo fi(citeListFile);
QCString input(fi.size()+1);
f.readBlock(input.data(),fi.size());
f.close();
input.at(fi.size())='\0';
int p=0,s;
//printf("input=[%s]\n",input.data());
while ((s=input.find('\n',p))!=-1)
{
QCString line = input.mid(p,s-p);
//printf("p=%d s=%d line=[%s]\n",p,s,line.data());
p=s+1;
if (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE;
else if (line.find("<!-- END BIBLIOGRAPH")!=-1) insideBib=FALSE;
else if (insideBib) doc+=line+"\n";
int i;
// determine text to use at the location of the @cite command
if (insideBib && (i=line.find("<a name=\"CITEREF_"))!=-1)
{
int j=line.find("\">[");
int k=line.find("]</a>");
if (j!=-1 && k!=-1)
{
QCString label = line.mid(i+17,j-i-17);
QCString number = line.mid(j+2,k-j-1);
CiteInfo *ci = m_entries.find(label);
//printf("label='%s' number='%s' => %p\n",label.data(),number.data(),ci);
if (ci)
{
ci->text = number;
}
}
}
}
示例8: file
bool
K2sendPlayer::bluePlay (QString * filename)
{
char buffer[buffer_size];
int bytes_done;
int file_len;
int bytes_sent;
int current_bytes_sent;
int rc;
int play_length;
bool stop = FALSE;
unsigned long long now;
fd_set rfds, wfds;
struct timeval tv;
K2sendPlayerCommand *cmd = 0;
K2sendPlayerCommand *new_cmd = 0;
K2sendStatusEvent *se = 0;
TagLib::MPEG::File mp3file (filename->latin1 ());
play_length = mp3file.audioProperties ()->length ();
QFile file (*filename);
kdDebug (200010) << "K2sendPlayer::bluePlay name=" << *filename << " lenght=" << play_length << endl;
setReset (0);
setLoudness (loud_filt);
setVolume (100 - volume);
if (!file.open (IO_ReadOnly)) {
QString msg = QString ("Error opening file ");
se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg);
//kdDebug(200010) << "post 34" << endl;
QApplication::postEvent (m_parent, se);
return FALSE;
}
se = new K2sendStatusEvent (K2sendStatusEvent::EventTitle, *filename);
//kdDebug(200010) << "post 35" << endl;
QApplication::postEvent (m_parent, se);
file_len = file.size ();
current_bytes_sent = bytes_sent = 0;
last_ticks = start_ticks = getTime ();
do {
/* check if we can send(write) or receive(read) data */
FD_ZERO (&rfds);
FD_SET (blue_sock, &rfds);
FD_ZERO (&wfds);
FD_SET (blue_sock, &wfds);
tv.tv_sec = 3;
tv.tv_usec = 0;
rc = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
if (rc < 1) {
kdDebug (200010) << "K2sendPlayer::bluePlay select()" << endl;
QString msg = QString ("Communication error");
se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
//kdDebug(200010) << "post 36" << endl;
QApplication::postEvent (m_parent, se);
blueClose ();
return FALSE;
}
/* are we allowed to write? */
if (FD_ISSET (blue_sock, &wfds)) {
buffer[0] = K2sendPlayerCommand::Data;
if (!(bytes_done = file.readBlock (buffer + 1, sizeof (buffer) - 1))) {
if (file.atEnd ()) {
kdDebug (200010) << "K2sendPlayer::bluePlay Error reading file " << endl;
QString msg = QString ("Error reading file");
se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
//kdDebug(200010) << "post 37" << endl;
QApplication::postEvent (m_parent, se);
}
}
else {
if (write (blue_sock, buffer, bytes_done + 1) != bytes_done + 1) {
kdDebug (200010) << "K2sendPlayer::bluePlay Error sending" << endl;
QString msg = QString ("Error sending data");
se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
//kdDebug(200010) << "post 38" << endl;
QApplication::postEvent (m_parent, se);
}
}
bytes_sent += bytes_done;
current_bytes_sent += bytes_done;
}
if (FD_ISSET (blue_sock, &rfds)) {
rc = read (blue_sock, buffer, sizeof (buffer));
kdDebug (200010) << "K2sendPlayer::bluePlay got data " << rc << " " << buffer[0] << " " << buffer[1] <<
endl;
/* handle commands */
switch (buffer[0]) {
case K2sendPlayerCommand::Buttons:
if ((buffer[1] & 1) == 1) {
volume += 10;
if (volume > 100)
//.........这里部分代码省略.........
示例9: readInfo
bool kfile_metadatPlugin::readInfo ( KFileMetaInfo& info, uint what )
{
bool readTech = false;
// add your "calculations" here
// if something goes wrong, "return false;"
if ( what & ( KFileMetaInfo::Fastest |
KFileMetaInfo::DontCare |
KFileMetaInfo::TechnicalInfo ) )
readTech = true;
if ( info.path().isEmpty() ) // remote file cannot be handled
return false;
if ( readTech )
{
KFileMetaInfoGroup group = appendGroup ( info, "Technical" );
char buffer[112];
QFile qf ( info.path() );
if ( ! qf.open ( IO_ReadOnly ) ||
( qf.readBlock ( buffer, 112 ) != 112 ) )
return false; // File cannot be read --> no meta info
qf.close();
try
{
comag::meta m ( ( const unsigned char * ) buffer );
appendItem ( group, "Title", QString::fromLatin1( m.gettitle().data() ) );
appendItem ( group, "Title Type", ( m.gettitle_type() == comag::meta::TT_TRANSMISSION ) ?
i18n ( "Transmission" ) :
( m.gettitle_type() == comag::meta::TT_STATION ) ?
i18n ( "Station" ) :
i18n ( "Unknown" ) );
#ifdef ENABLE_DATETIMETWOLINES
appendItem ( group, "Start Time", QTime ( m.getstart_time().hour,
m.getstart_time().minute,
m.getstart_time().second ) );
appendItem ( group, "Start Date", QDate ( m.getstart_date().year,
m.getstart_date().month,
m.getstart_date().day ) );
#else
appendItem ( group, "Start Time", QDateTime ( QDate ( m.getstart_date().year,
m.getstart_date().month,
m.getstart_date().day ),
QTime ( m.getstart_time().hour,
m.getstart_time().minute,
m.getstart_time().second ) ) );
#endif
appendItem ( group, "Duration", QTime ( m.getduration().hour,
m.getduration().minute,
m.getduration().second ) );
appendItem ( group, "Packets", m.getpackets() );
appendItem ( group, "Service", ( m.getservice() == comag::meta::S_RADIO ) ?
i18n ( "Radio" ) :
( m.getservice() == comag::meta::S_TV ) ?
i18n ( "TV" ) : i18n ( "Unknown" ) );
appendItem ( group, "PID", m.getpid() );
appendItem ( group, "Timer", ( unsigned long long ) ( m.gettimer() ) );
}
catch ( ... )
{
return false; // Exceptions simply means: no meta info
}
// and finally display it!
return true;
}
return false;
}