本文整理汇总了C++中QTemporaryFile::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::resize方法的具体用法?C++ QTemporaryFile::resize怎么用?C++ QTemporaryFile::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::resize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resize
void tst_QTemporaryFile::resize()
{
QTemporaryFile file;
file.setAutoRemove(true);
QVERIFY(file.open());
QVERIFY(file.resize(100));
QCOMPARE(QFileInfo(file.fileName()).size(), qint64(100));
file.close();
}
示例2: setSamples
void SignalDataSource::setSamples(float *samples,
qint64 count,
double sampleRate)
{
clean();
m_samples = samples;
m_count = count;
m_sampleRate = sampleRate;
qint64 spp = 2;
while (m_count / spp > 0) {
qint64 count = m_count / spp + ((m_count % spp) ? (1) : (0));
float *maximums;
float *minimums;
{
QTemporaryFile *file = new QTemporaryFile();
if (!file->open())
return ;
file->resize(count * sizeof(float));
maximums = (float *)(file->map(0, count * sizeof(float)));
}
{
QTemporaryFile *file = new QTemporaryFile();
if (!file->open())
return ;
file->resize(count * sizeof(float));
minimums = (float *)(file->map(0, count * sizeof(float)));
}
for (qint64 arrIndex = 0; arrIndex < count; ++arrIndex) {
qint64 sampleFirstIndex = arrIndex * spp;
qint64 sampleLastIndex = sampleFirstIndex + spp - 1;
if (sampleLastIndex >= m_count)
sampleLastIndex = m_count - 1;
double min;
double max;
min = max = m_samples[sampleFirstIndex];
for (int i = sampleFirstIndex + 1; i <= sampleLastIndex; ++i) {
if (m_samples[i] < min)
min = m_samples[i];
else if (m_samples[i] > max)
max = m_samples[i];
}
minimums[arrIndex] = min;
maximums[arrIndex] = max;
}
m_peakMaximums[spp] = maximums;
m_peakMinimums[spp] = minimums;
m_peakCount[spp] = count;
spp *= 2;
}
emit dataChanged();
}
示例3: providerTests
/*?
Test function for QUsbStorageGadgetProvider.
This test:
* Creates a QUsbStorageGadgetProvider.
* Does simple set-get tests on QUsbStorageGadgetProvider attributes.
* Activates and deactivates the gadget and ensures that the
required signals are emitted.
*/
void tst_QUsbStorageGadget::providerTests()
{
QUsbManager *manager = new QUsbManager(this);
// Test that there is no current usb gadget
QList<QUsbGadget *> activeGadgets = manager->activeGadgets();
QVERIFY(activeGadgets.count() == 0);
foreach (QUsbGadget *gadget, activeGadgets)
delete gadget;
// Test that the provider works as expected
{
QUsbStorageGadgetProvider *provider = new QUsbStorageGadgetProvider("Qt Extended");
// Set and test various attributes
{
if (provider->supportsProduct()) {
provider->setProduct("Qt Extended Product");
QVERIFY(provider->product() == "Qt Extended Product");
}
if (provider->supportsProductId()) {
provider->setProductId(0x5454);
QVERIFY(provider->productId() == 0x5454);
}
if (provider->supportsVendor()) {
provider->setVendor("Qt Extended Vendor");
QVERIFY(provider->vendor() == "Qt Extended Vendor");
}
if (provider->supportsVendorId()) {
provider->setVendorId(0x5454);
QVERIFY(provider->vendorId() == 0x5454);
}
QVERIFY(provider->backingStore().isEmpty());
provider->addBackingStore("/dev/partition1");
QVERIFY(provider->backingStore().count() == 1);
QVERIFY(provider->backingStore().contains("/dev/partition1"));
provider->addBackingStore("/dev/partition2");
QVERIFY(provider->backingStore().count() == 2);
QVERIFY(provider->backingStore().contains("/dev/partition1"));
QVERIFY(provider->backingStore().contains("/dev/partition2"));
provider->removeBackingStore("/dev/partition1");
QVERIFY(provider->backingStore().count() == 1);
QVERIFY(!provider->backingStore().contains("/dev/partition1"));
QVERIFY(provider->backingStore().contains("/dev/partition2"));
QStringList partitions;
partitions << "/dev/partition3" << "/dev/partition4";
provider->setBackingStore(partitions);
QVERIFY(provider->backingStore() == partitions);
provider->setBackingStore(QStringList());
QVERIFY(provider->backingStore().isEmpty());
}
// Activate and deactivate gadget
if (QProcess::execute("/sbin/modinfo g_file_storage")) {
QSKIP("This test requires the g_file_storage usb gadget driver", SkipSingle);
} else {
QVERIFY(manager->canActivate("Storage"));
QSignalSpy activateSpy(provider, SIGNAL(activated()));
QSignalSpy deactivateSpy(provider, SIGNAL(deactivated()));
QTemporaryFile backingStore;
backingStore.open();
backingStore.resize(5*1024*1024);
provider->addBackingStore(backingStore.fileName());
provider->activate();
//QTRY_VERIFY(activateSpy.count() + deactivateSpy.count() == 1);
activateSpy.clear();
deactivateSpy.clear();
QVERIFY(provider->active());
QList<QUsbGadget *> activeGadgets = manager->activeGadgets();
bool activated = false;
foreach (QUsbGadget *gadget, activeGadgets) {
if (gadget->gadget() == provider->gadget())
activated = true;
delete gadget;
}
//.........这里部分代码省略.........
示例4: createObjectsAndTypesPage
QString createObjectsAndTypesPage(PandaDocument* document)
{
static QTemporaryFile file(QDir::tempPath() + "/pandaRef_XXXXXX.html");
file.open();
file.resize(0);
QTextStream out(&file);
out << "<!DOCTYPE html>\n"
"<html lang=\"en\">\n"
" <head>\n"
" <meta charset=\"utf-8\">\n"
" <title>List of available objects and types for Panda</title>\n"
" </head>\n"
" <body>\n";
out << " <h1>Types</h1>\n";
auto dataEntriesList = DataFactory::entries();
std::sort(dataEntriesList.begin(), dataEntriesList.end(), dataTypeIdLessThan);
std::vector<EnrichedDataEntry> dataEntries;
// Copy entries and get additional info
for(auto d : dataEntriesList)
{
EnrichedDataEntry e = *d;
auto tmpData = DataFactory::create(d->fullType, "", "", nullptr);
if(tmpData)
{
e.description = tmpData->getDescription();
e.trait = tmpData->getDataTrait();
}
dataEntries.push_back(e);
}
for(const auto& d : dataEntries)
{
out << " <h2>" << QString::fromStdString(d.description) << "</h2>\n"
<< " <p>Type: " << toHtml(d.className) << "</p>\n"
<< " <p>Id: " << d.fullType << "</p>\n";
bool hasConversions = false;
for(const auto& d2 : dataEntries)
{
if(d.fullType == d2.fullType)
continue;
if(!d.trait || !d2.trait)
continue;
if(canConvert(d.trait, d2.trait))
{
if(!hasConversions)
{
out << " <p>Can be converted to: ";
hasConversions = true;
}
else
out << ", ";
out << QString::fromStdString(d2.description);
}
}
if(!hasConversions)
out << " <p>Has no known conversion";
out << "</p>\n";
auto widgets = DataWidgetFactory::getInstance()->getWidgetNames(d.fullType);
if(widgets.empty())
out << " <p>No widgets for this type</p>\n";
else
{
out << " <p>Widgets available: ";
bool first = true;
for(const auto& w : widgets)
{
if(first)
first = false;
else
out << ", ";
out << w;
}
out << "</p>\n";
}
}
out << " <h1>Objects</h1>\n";
std::vector<ObjectFactory::ClassEntry> objectsEntries;
for(const auto& object : ObjectFactory::registryMap())
objectsEntries.push_back(object.second);
std::sort(objectsEntries.begin(), objectsEntries.end(), objectsMenuLessThan);
for(const auto& o : objectsEntries)
{
out << " <h2>" << QString::fromStdString(o.menuDisplay) << "</h2>\n";
out << " <p>In module: " << toHtml(o.moduleName) << "</p>\n";
out << " <p>Type: " << toHtml(o.className) << "</p>\n";
out << " <p>" << QString::fromStdString(o.description) << "</p>\n";
if(o.creator)
//.........这里部分代码省略.........