Results 1 to 6 of 6

Thread: QUrl: file in the current dir

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QUrl: file in the current dir

    Getting absolute path to file is simple:
    QUrl("file://<path>/<filename>")
    But I want to get QUrl representation of file in the current directory. Something like QUrl("file://stylesheet.css") but this doesn't work.
    How to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QUrl: file in the current dir


  3. The following user says thank you to wysota for this useful post:

    Cupidvogel (25th February 2016)

  4. #3
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrl: file in the current dir

    I tried but unsuccessful. I want to apply my own css file to QWebFrame object.

    This works:
    Qt Code:
    1. QWebSettings *settings = QWebSettings::globalSettings();
    2. settings->setUserStyleSheetUrl(QUrl("file:///home/lirq/Programming/test/style.css") );
    To copy to clipboard, switch view to plain text mode 

    But this doesn't:
    Qt Code:
    1. QWebSettings *settings = QWebSettings::globalSettings();
    2. settings->setUserStyleSheetUrl( QUrl::fromLocalFile("style.css") );
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QUrl: file in the current dir

    Use an absolute path to the file, not relative one - file:///style.css and file:///home/lirq/.../style.css are two different paths.

  6. #5
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrl: file in the current dir

    In case of absolute path it's needed to get path to my application. How to do this?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QUrl: file in the current dir

    QCoreApplication::applicationDirPath() or you can probably simply use QFile::absolutePath() to get absolute path from relative one.

  8. The following 2 users say thank you to wysota for this useful post:

    Cupidvogel (25th February 2016), lirq (6th January 2009)

Similar Threads

  1. Need to know current file in qmake
    By juannm in forum Qt Programming
    Replies: 0
    Last Post: 4th April 2008, 13:50
  2. Qt designer plugin errors on OSX Leopard
    By mpotocnik in forum Qt Tools
    Replies: 10
    Last Post: 21st January 2008, 09:45
  3. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Replies: 15
    Last Post: 21st April 2007, 17:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.