Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with using QUrl class
Forum Updated to NodeBB v4.3 + New Features

Problem with using QUrl class

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.0k 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.
  • R Offline
    R Offline
    Romaniy
    wrote on last edited by
    #1

    Hello, everyone,
    I need to use dynamical patterns in my url address, but i have a problem with this.
    For example:

    when I use this declaration of my variable
    @QUrl url( "http://10.1.11.183:20/comm?cmd=update_text" );@

    My program works normal.

    But when I try to declare in the next way:
    @ QString comm_string(QString("http://%1:%2/comm?cmd=%3")
    .arg(comm_host)
    .arg(comm_port)
    .arg(comm_function));
    QUrl url( comm_string);@
    My program doesn't work normal.

    I see, that url normal recognize the string:
    @qDebug() << url.toString();@

    Gives this result:
    http://10.1.11.183:20/comm?cmd=update_text

    What do I do wrong??
    Thanks for your help

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xcoder
      wrote on last edited by
      #2

      Hi,
      Strange I tested your code, looks fine to me. What exactly are you expecting from the output?
      And what is worng with your result?

      For example I wrote this code:
      @
      QUrl url1("http://morf.lv:88/something?load=mod1");
      QString host = "morf.lv";
      int port = 88;
      QString func = "mod1";
      QUrl url2(
      QString("http://%1:%2/something?load=%3")
      .arg(host)
      .arg(port)
      .arg(func)
      );

      QString comm_string(QString("http://%1:%2/comm?cmd=%3")
                      .arg(host)
                      .arg(port)
                      .arg(func));
             QUrl url( comm_string);
      
      qDebug() << url << url1 << url2;
      qDebug() << url.toString() << url1.toString() << url2.toString();
      

      @

      And I got the output exactly how it should be:

      @
      [14:16:13 - 29/11/2013] QUrl( "http://morf.lv:88/comm?cmd=mod1" ) QUrl( "http://morf.lv:88/something?load=mod1" ) QUrl( "http://morf.lv:88/something?load=mod1" )

      [14:16:13 - 29/11/2013] "http://morf.lv:88/comm?cmd=mod1" "http://morf.lv:88/something?load=mod1" "http://morf.lv:88/something?load=mod1"
      @

      Only a biker knows why a dog sticks his head out of a car window.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Romaniy
        wrote on last edited by
        #3

        Thanks for response)
        Both my url looks fine too.
        But durring my application working, I see that progam, which located in this way - http://10.1.11.183:20/comm?cmd=update_text, has worked correct, if I specified the url like this:
        @QUrl url( "http://10.1.11.183:20/comm?cmd=update_text" );@
        and hasn't worked correct if I specified url like this:
        @ QString comm_string(QString("http://%1:%2/comm?cmd=%3")
        .arg(comm_host)
        .arg(comm_port)
        .arg(comm_function));
        QUrl url( comm_string);.@

        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