QUrl:fromLocalFile

533 views
Skip to first unread message

Luigi Ferraris

unread,
Dec 3, 2014, 4:51:31 AM12/3/14
to qtcon...@googlegroups.com
Hi to everyone.

I need to convert a local filename into a QUrl object, but I'm not able to get it.
I have used this code

LOCAL oUrl
oUrl := QUrl()
oUrl:fromLocalFile( "D:\mypath\otherpath\filename.ext" ) n.b. this is an example and I'm sure the file exists on the real path!

when I use HB_TRACE( HB_TR_ALWAYS, hb_ValToExp( oUrl:toLocalFile() ) ) I get an empty string
when I use HB_TRACE( HB_TR_ALWAYS, hb_ValToExp( oUrl:isValid() ) ) I get .F.

Where is my error? I'm missing something?

TIA
Luigi Ferraris

Alex Strickland

unread,
Dec 4, 2014, 2:29:44 AM12/4/14
to qtcon...@googlegroups.com

Luigi Ferraris

unread,
Dec 4, 2014, 4:45:38 AM12/4/14
to qtcon...@googlegroups.com
Il 04/12/2014 8.29, Alex Strickland ha scritto:
Maybe this helps:
Hi Alex,
many thanks for link; unfortunately, it didn't solves the problem.
AFAIK, :fromLocalFile converts from OS path\filename to url then I can get a string using (ie) myUrl:toString or myUrl:toLocalFile.
I don't know if is a Qt problem. If is there someone has C knowledge better than me, can create a simple program using QtCreator.
I'm trying to use it, but I get some errors.
The first one is related with this C line code QUrl url;
Qt designer say "aggregate 'QUrl url' has incomplete type and cannot be defined"

AAARGH

BR
Luigi Ferraris

Pritpal Bedi

unread,
Dec 4, 2014, 5:25:39 AM12/4/14
to qtcon...@googlegroups.com
Hi Luigi

Read the prototype of QUrl():fromLocalFile().
 
oUrl := QUrl()
oNewUrl := oUrl:fromLocalFile( "D:\mypath\otherpath\filename.ext" )
? oNewUrl:toLocalFile()


Pritpal Bedi
a student of software analysis & concepts 

Luigi Ferraris

unread,
Dec 4, 2014, 5:31:55 AM12/4/14
to qtcon...@googlegroups.com
Il 04/12/2014 11.25, Pritpal Bedi ha scritto:
> Read the prototype of QUrl():fromLocalFile().
You are right !!!! I'm a great newbe!!!
Thanks

BR
Luigi

Luigi Ferraris

unread,
Dec 4, 2014, 6:53:44 AM12/4/14
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi Pritpal,
many thanks for your answer
oUrl := QUrl():fromLocalFile( "device:\somePath\file.ext" ) works.

While I'm swimming in the sea, I found these problems:

1) QFileInfo
   LOCAL oFile := QFile( "device:\somePath\file.ext" )
   HB_TRACE( HB_TR_ALWAYS, "A(1) >" + oFile:fileName() )
OK, it returns the right value
   HB_TRACE( HB_TR_ALWAYS, "A(2) >" + hb_ValToExp( oFile:exists() ) ) OK, it returns .T. because file exists

   1.a) oFile := QFileInfo( "device:\somePath\file.ext" )
   HB_TRACE( HB_TR_ALWAYS, "A(1) >" + oFile:filePath() )
wrong it returns an empty string
   HB_TRACE( HB_TR_ALWAYS, "A(2) >" + hb_ValToExp( oFile:exists() ) ) wrong it returns .F.

   1.b) oFile := QFileInfo( QFile( "device:\somePath\file.ext" ) )
   HB_TRACE( HB_TR_ALWAYS, "A(1) >" + oFile:filePath() )
wrong it returns an empty string
   HB_TRACE( HB_TR_ALWAYS, "A(2) >" + hb_ValToExp( oFile:exists() ) ) wrong it returns .F.

2) QSoundEffect (nb. I'm using Qt 5.3.2, I see many if QT_VERSION >= into QsoundEffect.cpp )
  2.a) :IsLoaded() return .F., but I can hear the music; I have used this method before :play() not after
  2.b) :supportedMimeTypes() is not coded into QsoudEffect.qth; can be usefull? I think yes: in this way (probably) we can know if a "file" can be played.

BR
Luigi

Reply all
Reply to author
Forward
0 new messages