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


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

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


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

示例1: cfg

QWhereabouts *NeoGpsPlugin::create(const QString &source)
{
    qLog(Hardware) << __PRETTY_FUNCTION__;
    QString path = source;
    if (path.isEmpty()) {
#ifdef NMEA_GPS_DEVICE
        path = NMEA_GPS_DEVICE;
#endif
        QSettings cfg("Trolltech",  "Whereabouts");
        cfg.beginGroup("Hardware");
        path = cfg.value("Device", path).toString();
    }

    QFile *sourceFile = new QFile(path, this);
    if (!sourceFile->open(QIODevice::ReadOnly)) {
        QMessageBox::warning( 0,tr("Mappingdemo"),tr("Cannot open GPS device at %1").arg(path),
            QMessageBox::Ok,  QMessageBox::Ok);
        qWarning() << "Cannot open GPS device at" << path;
        delete sourceFile;
        return 0;
    }

    QNmeaWhereabouts *whereabouts = new QNmeaWhereabouts(QNmeaWhereabouts::RealTimeMode, this);
    whereabouts->setSourceDevice(sourceFile);

    // QFile does not emit readyRead(), so we must call
    // newDataAvailable() when necessary
    QSocketNotifier *notifier = new QSocketNotifier(sourceFile->handle(), QSocketNotifier::Read, this);
    connect(notifier, SIGNAL(activated(int)),
              whereabouts, SLOT(newDataAvailable()));

    return whereabouts;
}
开发者ID:Camelek,项目名称:qtmoko,代码行数:33,代码来源:neogpsplugin.cpp

示例2: on_sendBtn_clicked

void MainWindow::on_sendBtn_clicked()
{
    QFile *file = new QFile(QFileDialog::getOpenFileName(this, tr("Pick A Song To Send"), 0, tr("Music (*.wav)")));
    if (file->exists())
    {
        file->open(QIODevice::ReadOnly);
        ClientSend((HANDLE) _get_osfhandle(file->handle()));
    }
}
开发者ID:SpenserL,项目名称:WirelessAudio,代码行数:9,代码来源:mainwindow.cpp

示例3: tryEvdevDevice

void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device)
{
    QFile *qfile = new QFile(this);
    unsigned char evbits[BITS2BYTES(EV_MAX)];
    int fd;

    qfile->setFileName(device);
    if (!qfile->open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {
        delete qfile;
        return;
    }

    fd = qfile->handle();
    if (fd == -1) {
        delete qfile;
        return;
    }

    if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evbits) < 0) {
        delete qfile;
        return;
    }

    // Check that this input device has switches
    if (!TEST_BIT(EV_SW, evbits)) {
        delete qfile;
        return;
    }

    unsigned char swbit[BITS2BYTES(EV_MAX)];
    if (ioctl(fd, EVIOCGBIT(EV_SW, SW_CNT), swbit) < 0) {
        delete qfile;
        return;
    }

    // Check that there is a tablet mode switch here
    if (!TEST_BIT(SW_TABLET_MODE, swbit)) {
        delete qfile;
        return;
    }

    // Found an appropriate device - start monitoring it
    QSocketNotifier *sn = new QSocketNotifier(fd, QSocketNotifier::Read, qfile);
    sn->setEnabled(true);
    QObject::connect(sn, SIGNAL(activated(int)), this, SLOT(evdevEvent()));

    evdevFile = qfile;
    present = true;

    // Initialise initial tablet mode state
    unsigned long state[BITS2BYTES(SW_MAX)];
    if (ioctl(fd, EVIOCGSW(SW_MAX), state) < 0)
        return;

    evdevTabletMode = TEST_BIT(SW_TABLET_MODE, state);
}
开发者ID:BrandonSchaefer,项目名称:framework,代码行数:56,代码来源:mimhwkeyboardtracker.cpp

示例4: nostderr

void nostderr(QString dir)
{
    // redirect stderr to a file
    QFile *fp = new QFile(QString("%1/goldencheetah.log").arg(dir));
    if (fp->open(QIODevice::WriteOnly|QIODevice::Truncate) == true) {
        close(2);
        if(dup(fp->handle()) == -1) fprintf(stderr, "GoldenCheetah: cannot redirect stderr\n");
    } else {
        fprintf(stderr, "GoldenCheetah: cannot redirect stderr\n");
    }
}
开发者ID:ChangSpivey,项目名称:GoldenCheetah,代码行数:11,代码来源:main.cpp

示例5:

ZipReader::ZipReader(QIODevice* device) :
	m_archive(0)
{
	QFile* file = qobject_cast<QFile*>(device);
	if (file) {
		m_archive = zip_fdopen(file->handle(), 0, 0);
		if (m_archive) {
			readFileInfo();
		}
	}
}
开发者ID:crowforge,项目名称:focuswriter,代码行数:11,代码来源:zip_reader.cpp

示例6: setFileAsSparse

void File::setFileAsSparse(const QFile& file)
{
   // TODO: Do we need that on linux? see 'fallocate(..)',
   #ifdef Q_OS_WIN32
      DWORD bytesWritten;
      HANDLE hdl = (HANDLE)_get_osfhandle(file.handle());
      // To avoid to initialize all the file, when you seek at the end of a file then you write some data the file will be initialized without this call.
      // File initialization can take several minutes for a large file (> 5 GiB).
      // See : http://msdn.microsoft.com/en-us/library/aa364596%28v=vs.85%29.aspx
      if (!DeviceIoControl(hdl, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &bytesWritten, NULL))
         L_WARN("DeviceIoControl(..) failed");
   #endif
}
开发者ID:Ummon,项目名称:D-LAN,代码行数:13,代码来源:File.cpp

示例7: isColoringPossible

    /*!
     Returns true if it's suitable to send colored output to \c stderr.
     */
    inline bool isColoringPossible() const
    {
#           if defined(Q_OS_WIN)
        /* Windows doesn't at all support ANSI escape codes, unless
         * the user install a "device driver". See the Wikipedia links in the
         * class documentation for details. */
        return false;
#           else
        /* We use QFile::handle() to get the file descriptor. It's a bit unsure
         * whether it's 2 on all platforms and in all cases, so hopefully this layer
         * of abstraction helps handle such cases. */
        return isatty(m_out.handle());
#           endif
    }
开发者ID:RobinWuDev,项目名称:Qt,代码行数:17,代码来源:qcoloroutput.cpp

示例8: fsync

bool fsync(QFile &file) noexcept(false)
{
    const int handle = file.handle();
#ifdef Q_OS_WIN
    return false;
#elif defined(Q_OS_MAC)
    if (::fcntl(handle, F_FULLFSYNC) == -1) {
        throw IOException::withCurrentErrno();
    }
#else
    if (::fsync(handle) == -1) {
        throw IOException::withCurrentErrno();
    }
#endif
    return true;
}
开发者ID:MUME,项目名称:MMapper,代码行数:16,代码来源:io.cpp

示例9: 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

示例10: on_openIncoming_clicked

void MainWindow::on_openIncoming_clicked()
{
    if (ClientReceiveSetup() == 0)
    {
        QFile *file = new QFile(QFileDialog::getSaveFileName(this, tr("Save song as"), 0, tr("Music (*.wav)")));
        if (file->fileName() != NULL)
        {
            ui->openIncoming->setEnabled(false);
            ui->disconnectIncoming->setEnabled(true);
            file->open(QIODevice::WriteOnly);
            ClientListen((HANDLE) _get_osfhandle(file->handle()));
        } else
        {
            ClientCleanup();
        }
    }
}
开发者ID:SpenserL,项目名称:WirelessAudio,代码行数:17,代码来源:mainwindow.cpp

示例11: parseSingleConfigFile

void KConfigINIBackEnd::parseSingleConfigFile(QFile &rFile, KEntryMap *pWriteBackMap, bool bGlobal, bool bDefault)
{
    const char *s;   // May get clobbered by sigsetjump, but we don't use them afterwards.
    const char *eof; // May get clobbered by sigsetjump, but we don't use them afterwards.
    QByteArray data;

    if(!rFile.isOpen()) // come back, if you have real work for us ;->
        return;

    // using kdDebug() here leads to an infinite loop
    // remove this for the release, aleXXX
    // qWarning("Parsing %s, global = %s default = %s",
    //           rFile.name().latin1(), bGlobal ? "true" : "false", bDefault ? "true" : "false");

    QCString aCurrentGroup("<default>");

    unsigned int ll = localeString.length();

#ifdef HAVE_MMAP
    static volatile const char *map;
    map = (const char *)mmap(0, rFile.size(), PROT_READ, MAP_PRIVATE, rFile.handle(), 0);

    if(map != MAP_FAILED)
    {
        s = (const char *)map;
        eof = s + rFile.size();

#ifdef SIGBUS
        struct sigaction act;
        act.sa_handler = mmap_sigbus_handler;
        sigemptyset(&act.sa_mask);
#ifdef SA_ONESHOT
        act.sa_flags = SA_ONESHOT;
#else
        act.sa_flags = SA_RESETHAND;
#endif
        sigaction(SIGBUS, &act, &mmap_old_sigact);

        if(sigsetjmp(mmap_jmpbuf, 1))
        {
            qWarning("SIGBUS while reading %s", rFile.name().latin1());
            munmap((char *)map, rFile.size());
            sigaction(SIGBUS, &mmap_old_sigact, 0);
            return;
        }
#endif
    }
    else
#endif
    {
        rFile.at(0);
        data = rFile.readAll();
        s = data.data();
        eof = s + data.size();
    }

    bool fileOptionImmutable = false;
    bool groupOptionImmutable = false;
    bool groupSkip = false;

    int line = 0;
    for(; s < eof; s++)
    {
        line++;

        while((s < eof) && isspace(*s) && (*s != '\n'))
            s++; // skip leading whitespace, shouldn't happen too often

        // skip empty lines, lines starting with #
        if((s < eof) && ((*s == '\n') || (*s == '#')))
        {
        sktoeol: // skip till end-of-line
            while((s < eof) && (*s != '\n'))
                s++;
            continue; // Empty or comment or no keyword
        }
        const char *startLine = s;

        if(*s == '[') // group
        {
            // In a group [[ and ]] have a special meaning
            while((s < eof) && (*s != '\n'))
            {
                if(*s == ']')
                {
                    if((s + 1 < eof) && (*(s + 1) == ']'))
                        s++; // Skip "]]"
                    else
                        break;
                }

                s++; // Search till end of group
            }
            const char *e = s;
            while((s < eof) && (*s != '\n'))
                s++; // Search till end of line / end of file
            if((e >= eof) || (*e != ']'))
            {
                fprintf(stderr, "Invalid group header at %s:%d\n", rFile.name().latin1(), line);
                continue;
//.........这里部分代码省略.........
开发者ID:serghei,项目名称:kde3-kdelibs,代码行数:101,代码来源:kconfigbackend.cpp

示例12: QFileToifstream

std::ifstream QFileToifstream(QFile & file) {
    Q_ASSERT(file.isReadable());
    return std::ifstream(::_fdopen(file.handle(), "r"));
}
开发者ID:WarlockD,项目名称:QtPDP8,代码行数:4,代码来源:mainwindow.cpp

示例13: scan

void QInputDeviceScanner::scan()
{
    for( int index = 0; index < MAX_INPUT_DEVICES; index++ )
    {
        QString devInput = QString("/dev/input");

        QString devEvent = devInput + "/event" + QString::number(index);

        QFile fileEvent;

        fileEvent.setFileName(devEvent);

        if( fileEvent.open(QIODevice::ReadOnly) )
        {
            char name[256] = "Unknown";
            char phys[256] = "";

            if( ::ioctl(fileEvent.handle(), EVIOCGNAME(sizeof(name)), name) < 0 )
            {
//                qWarning("Cannot get the name of device");
            }

            if( ::ioctl(fileEvent.handle(), EVIOCGPHYS(sizeof(phys)), phys) < 0 )
            {
//                qWarning("Cannot get the physical location");
            }

            QString deviceName = QString(name);
            QString devicePhys = QString(phys);

            if( devicePhys.startsWith("usb-dev") )
            {
                unsigned long evbit[NBITS(EV_MAX + 1)];

                if( ::ioctl(fileEvent.handle(), EVIOCGBIT(0, sizeof(evbit)), evbit) >= 0 )
                {
                    if( IS_BIT_SET(EV_REL, evbit) )
                    {
                        qDebug() << QString("Found Mouse: ") << devEvent;

                        m_listOfMouse.append(devEvent);
                    }
                    else if( IS_BIT_SET(EV_KEY, evbit) &&
                             ! IS_BIT_SET(EV_REL, evbit) &&
                             ! IS_BIT_SET(EV_ABS, evbit) )
                    {
                        qDebug() << QString("Found Keyboard: ") << devEvent;

                        m_listOfKeyboard.append(devEvent);
                    }
                }
            }
            else if(deviceName.contains("M-RCU - Builtin"))
            {
                qDebug() << QString("Found Motion: ") << devEvent;
                m_listOfMotion.append(devEvent);
            }

            fileEvent.close();
        }
    }
}
开发者ID:RS102839,项目名称:qt,代码行数:62,代码来源:qinputdevicescanner.cpp

示例14: save

bool TextBuffer::save (const QString &filename)
{
  // codec must be set!
  Q_ASSERT (m_textCodec);

  /**
   * construct correct filter device and try to open
   */
  QIODevice *file = KFilterDev::deviceForFile (filename, m_mimeTypeForFilterDev, false);
  if (!file->open (QIODevice::WriteOnly)) {
    delete file;
    return false;
  }

  /**
   * construct stream + disable Unicode headers
   */
  QTextStream stream (file);
  stream.setCodec (QTextCodec::codecForName("UTF-16"));

  // set the correct codec
  stream.setCodec (m_textCodec);

  // generate byte order mark?
  stream.setGenerateByteOrderMark (generateByteOrderMark());

  // our loved eol string ;)
  QString eol = "\n"; //m_doc->config()->eolString ();
  if (endOfLineMode() == eolDos)
    eol = QString ("\r\n");
  else if (endOfLineMode() == eolMac)
    eol = QString ("\r");

  // just dump the lines out ;)
  for (int i = 0; i < m_lines; ++i)
  {
    // get line to save
    Kate::TextLine textline = line (i);

    // strip trailing spaces
    if (m_removeTrailingSpaces)
    {
      int lastChar = textline->lastChar();
      if (lastChar > -1)
      {
        stream << textline->text().left (lastChar+1);
      }
    }
    else // simple, dump the line
      stream << textline->text();

    // append correct end of line string
    if ((i+1) < m_lines)
      stream << eol;
  }

  // flush stream
  stream.flush ();

  // close and delete file
  file->close ();
  delete file;

#ifndef Q_OS_WIN
  // ensure that the file is written to disk
  // we crete new qfile, as the above might be wrapper around compression
  QFile syncFile (filename);
  syncFile.open (QIODevice::ReadOnly);

#ifdef HAVE_FDATASYNC
  fdatasync (syncFile.handle());
#else
  fsync (syncFile.handle());
#endif
#endif

  // did save work?
  bool ok = stream.status() == QTextStream::Ok;

  // remember this revision as last saved if we had success!
  if (ok)
    m_history.setLastSavedRevision ();

  // report CODEC + ERRORS
  kDebug (13020) << "Saved file " << filename << "with codec" << m_textCodec->name()
    << (ok ? "without" : "with") << "errors";

  // emit signal on success
  if (ok)
    emit saved (filename);

  // return success or not
  return ok;
}
开发者ID:rtaycher,项目名称:kate,代码行数:94,代码来源:katetextbuffer.cpp

示例15: isConsoleDevice

bool ConsoleDevice::isConsoleDevice(QIODevice *pDevice)
{
    QFile* file = qobject_cast<QFile*>(pDevice);
    return file && (file->handle() == STDOUT_FILENO || file->handle() == STDERR_FILENO);
}
开发者ID:koloboid,项目名称:qk-cpp,代码行数:5,代码来源:consoledevice.cpp


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