本文整理汇总了C++中QUrl::isRelative方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::isRelative方法的具体用法?C++ QUrl::isRelative怎么用?C++ QUrl::isRelative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::isRelative方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setSource
/**
* Supports only rendering of local files and resources that can be downloaded over
* the http protocol. In the latter case the download gets started.
*/
void TextBrowser::setSource (const QUrl& url)
{
bool relativeUrl = url.isRelative();
if (!relativeUrl)
d->source = url; // last set absolute url
QString name = url.toString();
if (url.scheme() == QLatin1String("http")) {
// start the download but do not call setSource() of the base
// class because we must wait until the data are available.
// The slot done() is invoked automatically then.
d->http->setHost(url.host());
d->http->get(url.path(), 0);
} else if (d->source.scheme() == QLatin1String("http")) {
// relative hyperlink in previously downloaded a HTML page
d->source = d->source.resolved(url);
d->http->get(url.path(), 0);
} else {
QUrl resolved = url;
#if defined (Q_OS_WIN)
if (url.scheme() == QLatin1String("file") && !url.isRelative()) {
QString auth = url.authority();
QString path = url.path();
//If we click on a hyperlink with a reference to an absolute file name
//then we get a string that cannot be used to open the file. So we try
//to reproduce the original url.
if (!auth.isEmpty() && !path.isEmpty()) {
QString fileName = auth + QLatin1Char(':') + path;
resolved = QUrl::fromLocalFile(fileName);
}
}
#endif
QTextBrowser::setSource(resolved);
}
}
示例2: evaluateSingleton
Item DocumentURIFN::evaluateSingleton(const DynamicContext::Ptr &context) const
{
const Item node(m_operands.first()->evaluateSingleton(context));
if(node)
{
const QUrl documentURI(node.asNode().documentUri());
if(documentURI.isValid())
{
if(documentURI.isEmpty())
return Item();
else
{
Q_ASSERT_X(!documentURI.isRelative(), Q_FUNC_INFO,
"The document URI must be absolute.");
return toItem(AnyURI::fromValue(documentURI));
}
}
else
return Item();
}
else
return Item();
}
示例3: isValidLocalPath
bool Utils::isValidLocalPath(const QString &value)
{
QUrl url;
url.setUrl(value);
return (url.isValid() && (url.isRelative() || url.scheme().toLower() == "file") );
}
示例4: addRss
void RSSWidget::addRss()
{
if (!m_view) {
return;
}
if (QPushButton* button = qobject_cast<QPushButton*>(sender())) {
QUrl url = button->property("rss-url").toUrl();
if (url.isRelative()) {
url = m_view->page()->mainFrame()->baseUrl().resolved(url);
}
if (!url.isValid()) {
return;
}
QString title = button->property("rss-title").toString();
if (title.isEmpty()) {
title = m_view->url().host();
}
RSSNotification* notif = new RSSNotification(title, url, m_view);
m_view->addNotification(notif);
close();
}
}
示例5: loadResource
QVariant HelpBrowser::loadResource(int type, const QUrl &name){
QTextBrowser::loadResource(type, name);
// if (name.scheme() == "qthelp")
// return QVariant(m_helpEngine->fileData(name));
// else
// return QTextBrowser::loadResource(type, name);
return m_helpEngine->fileData(name);
QByteArray ba;
if (type < 10 && m_helpEngine) {
QUrl url(name);
if (name.isRelative())
url = source().resolved(url);
ba = m_helpEngine->fileData(url);
}
return ba;
}
示例6: loadUrl
/*!
Load the QDeclarativeComponent from the provided \a url.
Ensure that the URL provided is full and correct, in particular, use
\l QUrl::fromLocalFile() when loading a file from the local filesystem.
*/
void QDeclarativeComponent::loadUrl(const QUrl &url)
{
Q_D(QDeclarativeComponent);
d->clear();
if (url.isRelative() && !url.isEmpty())
d->url = d->engine->baseUrl().resolved(url);
else
d->url = url;
if (url.isEmpty()) {
QDeclarativeError error;
error.setDescription(tr("Invalid empty URL"));
d->state.errors << error;
return;
}
QDeclarativeCompositeTypeData *data =
QDeclarativeEnginePrivate::get(d->engine)->typeManager.get(d->url);
if (data->status == QDeclarativeCompositeTypeData::Waiting
|| data->status == QDeclarativeCompositeTypeData::WaitingResources)
{
d->typeData = data;
d->typeData->addWaiter(d);
d->progress = data->progress;
} else {
d->fromTypeData(data);
d->progress = 1.0;
}
emit statusChanged(status());
emit progressChanged(d->progress);
}
示例7: isRelative
bool QUrlProto::isRelative() const
{
QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
if (item)
return item->isRelative();
return false;
}
示例8: searchForResourceSearchPath
QUrl searchForResourceSearchPath(const QUrl& baseUrl,
const QUrl& url,
const QStringList& searchPath)
{
if (url.isRelative()) {
if (!baseUrl.isLocalFile()) {
return baseUrl.resolved(url);
}
auto path = url.path();
if (!path.startsWith("/")) {
auto resolvedUrl = baseUrl.resolved(url);
if (QFile::exists(resolvedUrl.toLocalFile())) {
return resolvedUrl;
}
} else if (!path.contains("/../")) {
auto pathRelPart = path.split(QRegularExpression("^/+"))[1];
for (const auto& str : searchPath) {
auto dir = QDir(str);
auto absPath = QDir::cleanPath(dir.absoluteFilePath(pathRelPart));
if (QFile::exists(absPath)) {
return QUrl::fromLocalFile(absPath);
}
}
return QUrl();
} else {
return QUrl();
}
}
return url;
}
示例9: copyResource
QString VWebUtils::copyResource(const QUrl &p_url, const QString &p_folder) const
{
Q_ASSERT(!p_url.isRelative());
QDir dir(p_folder);
if (!dir.exists()) {
VUtils::makePath(p_folder);
}
QString file = p_url.isLocalFile() ? p_url.toLocalFile() : p_url.toString();
QString fileName = VUtils::fileNameFromPath(file);
fileName = VUtils::getFileNameWithSequence(p_folder, fileName, true);
QString targetFile = dir.absoluteFilePath(fileName);
bool succ = false;
if (p_url.scheme() == "https" || p_url.scheme() == "http") {
// Download it.
QByteArray data = VDownloader::downloadSync(p_url);
if (!data.isEmpty()) {
succ = VUtils::writeFileToDisk(targetFile, data);
}
} else if (QFileInfo::exists(file)) {
// Do a copy.
succ = VUtils::copyFile(file, targetFile, false);
}
return succ ? targetFile : QString();
}
示例10: resolvedUrl
QUrl QQmlContextData::resolvedUrl(const QUrl &src)
{
QQmlContextData *ctxt = this;
QUrl resolved;
if (src.isRelative() && !src.isEmpty()) {
if (ctxt) {
while(ctxt) {
if (ctxt->url().isValid())
break;
else
ctxt = ctxt->parent;
}
if (ctxt)
resolved = ctxt->url().resolved(src);
else if (engine)
resolved = engine->baseUrl().resolved(src);
}
} else {
resolved = src;
}
if (resolved.isEmpty()) //relative but no ctxt
return resolved;
if (engine && engine->urlInterceptor())
resolved = engine->urlInterceptor()->intercept(resolved, QQmlAbstractUrlInterceptor::UrlString);
return resolved;
}
示例11: loadInternal
void OffscreenSurface::loadInternal(const QUrl& qmlSource,
bool createNewContext,
QQuickItem* parent,
const QmlContextObjectCallback& callback) {
if (QThread::currentThread() != thread()) {
qFatal("Called load on a non-surface thread");
}
// Synchronous loading may take a while; restart the deadlock timer
QMetaObject::invokeMethod(qApp, "updateHeartbeat", Qt::DirectConnection);
if (!getRootItem()) {
_sharedObject->create(this);
}
QUrl finalQmlSource = qmlSource;
if ((qmlSource.isRelative() && !qmlSource.isEmpty()) || qmlSource.scheme() == QLatin1String("file")) {
finalQmlSource = getSurfaceContext()->resolvedUrl(qmlSource);
}
if (!getRootItem()) {
_sharedObject->setObjectName(finalQmlSource.toString());
}
auto targetContext = contextForUrl(finalQmlSource, parent, createNewContext);
auto qmlComponent = new QQmlComponent(getSurfaceContext()->engine(), finalQmlSource, QQmlComponent::PreferSynchronous);
if (qmlComponent->isLoading()) {
connect(qmlComponent, &QQmlComponent::statusChanged, this,
[=](QQmlComponent::Status) { finishQmlLoad(qmlComponent, targetContext, parent, callback); });
return;
}
finishQmlLoad(qmlComponent, targetContext, parent, callback);
}
示例12: loadUrl
/*!
Load the QDeclarativeComponent from the provided \a url.
Ensure that the URL provided is full and correct, in particular, use
\l QUrl::fromLocalFile() when loading a file from the local filesystem.
*/
void QDeclarativeComponent::loadUrl(const QUrl &url)
{
Q_D(QDeclarativeComponent);
d->clear();
if ((url.isRelative() && !url.isEmpty())
|| url.scheme() == QLatin1String("file")) // Workaround QTBUG-11929
d->url = d->engine->baseUrl().resolved(url);
else
d->url = url;
if (url.isEmpty()) {
QDeclarativeError error;
error.setDescription(tr("Invalid empty URL"));
d->state.errors << error;
return;
}
QDeclarativeTypeData *data = QDeclarativeEnginePrivate::get(d->engine)->typeLoader.get(d->url);
if (data->isCompleteOrError()) {
d->fromTypeData(data);
d->progress = 1.0;
} else {
d->typeData = data;
d->typeData->registerCallback(d);
d->progress = data->progress();
}
emit statusChanged(status());
emit progressChanged(d->progress);
}
示例13: fromLocalFile
static inline QUrl ensureAbsoluteUrl(const QUrl &url)
{
if (!url.isRelative())
return url;
return QUrl::fromLocalFile(QFileInfo(url.toLocalFile()).absoluteFilePath());
}
示例14: announceUnparsedText
ItemType::Ptr ResourceLoader::announceUnparsedText(const QUrl &uri)
{
Q_ASSERT(uri.isValid());
Q_ASSERT(!uri.isRelative());
Q_UNUSED(uri); /* Needed when compiling in release mode. */
return ItemType::Ptr();
}
示例15: announceDocument
SequenceType::Ptr ResourceLoader::announceDocument(const QUrl &uri, const Usage)
{
Q_ASSERT(uri.isValid());
Q_ASSERT(!uri.isRelative());
Q_UNUSED(uri); /* Needed when compiling in release mode. */
return SequenceType::Ptr();
}