コード例 #1
0
void QQuickLoaderPrivate::setInitialState(QObject *obj)
{
    Q_Q(QQuickLoader);

    QQuickItem *item = qmlobject_cast<QQuickItem*>(obj);
    if (item) {
        // If the item doesn't have an explicit size, but the Loader
        // does, then set the item's size now before bindings are
        // evaluated, otherwise we will end up resizing the item
        // later and triggering any affected bindings/anchors.
        if (widthValid && !QQuickItemPrivate::get(item)->widthValid)
            item->setWidth(q->width());
        if (heightValid && !QQuickItemPrivate::get(item)->heightValid)
            item->setHeight(q->height());
        item->setParentItem(q);
    }
    if (obj) {
        QQml_setParent_noEvent(itemContext, obj);
        QQml_setParent_noEvent(obj, q);
        itemContext = 0;
    }

    if (initialPropertyValues.isUndefined())
        return;

    QQmlComponentPrivate *d = QQmlComponentPrivate::get(component);
    Q_ASSERT(d && d->engine);
    QV4::ExecutionEngine *v4 = qmlGlobalForIpv.engine();
    Q_ASSERT(v4);
    QV4::Scope scope(v4);
    QV4::ScopedValue ipv(scope, initialPropertyValues.value());
    d->initializeObjectWithInitialProperties(qmlGlobalForIpv, ipv, obj);
}
コード例 #2
0
/*!
    \qmlmethod object QtQuick::Loader::setSource(url source, object properties)

    Creates an object instance of the given \a source component that will have
    the given \a properties. The \a properties argument is optional.  The instance
    will be accessible via the \l item property once loading and instantiation
    is complete.

    If the \l active property is \c false at the time when this function is called,
    the given \a source component will not be loaded but the \a source and initial
    \a properties will be cached.  When the loader is made \l active, an instance of
    the \a source component will be created with the initial \a properties set.

    Setting the initial property values of an instance of a component in this manner
    will \b{not} trigger any associated \l{Behavior}s.

    Note that the cached \a properties will be cleared if the \l source or \l sourceComponent
    is changed after calling this function but prior to setting the loader \l active.

    Example:
    \table
    \row
    \li
    \qml
    // ExampleComponent.qml
    import QtQuick 2.0
    Rectangle {
        id: rect
        color: "red"
        width: 10
        height: 10

        Behavior on color {
            NumberAnimation {
                target: rect
                property: "width"
                to: (rect.width + 20)
                duration: 0
            }
        }
    }
    \endqml
    \li
    \qml
    // example.qml
    import QtQuick 2.0
    Item {
        Loader {
            id: squareLoader
            onLoaded: console.log(squareLoader.item.width); // prints [10], not [30]
        }

        Component.onCompleted: {
            squareLoader.setSource("ExampleComponent.qml", { "color": "blue" });
            // will trigger the onLoaded code when complete.
        }
    }
    \endqml
    \endtable

    \sa source, active
*/
void QQuickLoader::setSource(QQmlV4Function *args)
{
    Q_ASSERT(args);
    Q_D(QQuickLoader);

    bool ipvError = false;
    args->setReturnValue(QV4::Encode::undefined());
    QV4::Scope scope(args->v4engine());
    QV4::ScopedValue ipv(scope, d->extractInitialPropertyValues(args, this, &ipvError));
    if (ipvError)
        return;

    d->clear();
    QUrl sourceUrl = d->resolveSourceUrl(args);
    if (!ipv->isUndefined()) {
        d->disposeInitialPropertyValues();
        d->initialPropertyValues = ipv.asReturnedValue();
        d->qmlGlobalForIpv = args->qmlGlobal();
    }

    setSource(sourceUrl, false); // already cleared and set ipv above.
}
コード例 #3
0
ファイル: Network.C プロジェクト: autodataming/IQmol
in_addr_t HostLookup(QString const& hostname)
{
   in_addr_t address(INADDR_NONE);

#ifdef WIN32

   // This can only handle IPv4 addresses and should only be used when
   // inet_ntop is unavailable.
   QString octet("(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])");
   QRegExpValidator ipv4Validator(0);
   ipv4Validator.setRegExp(QRegExp(
      "^" + octet + "\\." + octet + "\\." + octet + "\\." + octet + "$"));

   int pos;
   QString tmp(hostname);

   if (ipv4Validator.validate(tmp,pos) == QValidator::Acceptable) {
      address = inet_addr(hostname.toLatin1().data());
      if (address == INADDR_ANY || address == INADDR_NONE) {
         throw InvalidHostname(hostname);
      }
   }else {
      struct hostent* host;
      host = gethostbyname(hostname.toLatin1().data());
      if (host->h_addrtype == AF_INET6) {
         throw Exception("IPv6 addresses are not supported");
      }else if (host) {
         address = *(in_addr_t*)host->h_addr;
      }
   }

#else

   struct addrinfo hints, *res;
   int errcode;
   char addrstr[100];
   void *ptr(0);

   memset(&hints, 0, sizeof (hints));
   hints.ai_family = PF_UNSPEC;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags |= AI_CANONNAME;

   errcode = getaddrinfo(hostname.toLatin1().data(), NULL, &hints, &res);
   if (errcode != 0) throw InvalidHostname(hostname);
 
   inet_ntop(res->ai_family, res->ai_addr->sa_data, addrstr, 100);

   switch (res->ai_family) {
      case AF_INET:
         ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
         break;
      case AF_INET6:
         ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
         break;
   }

   inet_ntop(res->ai_family, ptr, addrstr, 100);
   address = inet_addr(addrstr);

   QString ipv((res->ai_family == PF_INET6) ? "IPv6 address:" : "IPv4 address:");
   QLOG_DEBUG() << ipv << QString(addrstr) << "=>" << QString(res->ai_canonname);

#endif

   return address;
}