Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to detect "url" type in QML/Javascript?
Forum Updated to NodeBB v4.3 + New Features

How to detect "url" type in QML/Javascript?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 469 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    Docs on url

    I am passing a QUrl from my C++ code to my javascript code. However, I cannot detect the type

    This does not work:

    if(obj instanceof url)
    

    This just detects that it is an object:

    if(typeof obj === "object")
    

    I need to know if the object is a url type. I am parsing objects in a recursive loop to build a properties list to feed to a model. So I am parsing into objects that contain urls. There are no properties on the url object. It just has a method for converting toString().

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      And this doesn't work either as javascript objects have a toString method:

      if(typeof obj.toString === 'function')
      

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by fcarney
        #3

        Okay, I have a contextObject with misc functions. I added this for detecting this:

        bool UtilFunctions::isUrl(QVariant obj)
        {
        if(obj.toUrl().isEmpty() || !obj.toUrl().isValid())
        return false;
        return true;
        }

        Edit:

        bool UtilFunctions::isUrl(QVariant obj)
        {
            if(obj.type() != QVariant::Url)
                return false;
            return true;
        }
        

        C++ is a perfectly valid school of magic.

        GrecKoG 1 Reply Last reply
        2
        • fcarneyF fcarney

          Okay, I have a contextObject with misc functions. I added this for detecting this:

          bool UtilFunctions::isUrl(QVariant obj)
          {
          if(obj.toUrl().isEmpty() || !obj.toUrl().isValid())
          return false;
          return true;
          }

          Edit:

          bool UtilFunctions::isUrl(QVariant obj)
          {
              if(obj.type() != QVariant::Url)
                  return false;
              return true;
          }
          
          GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          so return obj.type() == QVariant::Url; ;)

          fcarneyF 1 Reply Last reply
          2
          • GrecKoG GrecKo

            so return obj.type() == QVariant::Url; ;)

            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            @GrecKo Yeah, I changed my copy to that right after. Thanks for updating it!

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved