Problem with using QUrl class
-
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_textWhat do I do wrong??
Thanks for your help -
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"
@ -
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);.@