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. How to open a temporary file use QDesktopServices?
Forum Updated to NodeBB v4.3 + New Features

How to open a temporary file use QDesktopServices?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.3k Views 2 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.
  • L Offline
    L Offline
    ljc123456gogo
    wrote on last edited by ljc123456gogo
    #1

    I use QTemporaryFile to create a temporary file successfully. But I want to open it by QDesktopServices:

    QDesktopServices::openUrl(tempFile);
    

    The tempFile seems to be locked by the application. Even I find the tempFile in computer and try to open it Manually, but it can't be done. I try to copy it to other place, and it can be open.
    What should I do? Is there have any easy way to solve it?

    Keep Hungery, Keep Foolish!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @ljc123456gogo said:

      QTemporaryFile

      Hi
      as long as its not a .exe file, you should be able to
      use QTemporaryFile to get file name. delete the QTemporaryFile object to release file
      and reuse the tempname for a file you then create normally.
      There is also
      http://en.cppreference.com/w/cpp/io/c/tmpnam

      And dont call filename anything with setup. on windows, its forbidden. :)
      UAC eats it in win 10.

      L 1 Reply Last reply
      1
      • mrjjM mrjj

        @ljc123456gogo said:

        QTemporaryFile

        Hi
        as long as its not a .exe file, you should be able to
        use QTemporaryFile to get file name. delete the QTemporaryFile object to release file
        and reuse the tempname for a file you then create normally.
        There is also
        http://en.cppreference.com/w/cpp/io/c/tmpnam

        And dont call filename anything with setup. on windows, its forbidden. :)
        UAC eats it in win 10.

        L Offline
        L Offline
        ljc123456gogo
        wrote on last edited by
        #3

        @mrjj
        Hi.
        I want to use the QTemporaryFile because it has a good function for auto delect all created temporary file. As long as I delete the QTemporaryFile object, all temporary file created by it will be deleted. If I create the tempFile normally, I will not do the job easily. So I want to ask if there have any easy way to do that things?

        Keep Hungery, Keep Foolish!

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Not really as you want other process to open it.
          So you cannot have it locked in your app.

          So you will have to keep track of objects to delete on close.
          If was for your own app. then tempfile really good yes.

          1 Reply Last reply
          1
          • L Offline
            L Offline
            ljc123456gogo
            wrote on last edited by
            #5

            I found someone encounter the same problem as me and commit to QTBUG a long time ago: https://bugreports.qt.io/browse/QTBUG-10856
            Although the behaviour really is not bug and it is by design, but I think it is nessary and I hope QT to add a function for unlock temporary file to solve this problem in the future :)

            Keep Hungery, Keep Foolish!

            mrjjM 1 Reply Last reply
            0
            • L ljc123456gogo

              I found someone encounter the same problem as me and commit to QTBUG a long time ago: https://bugreports.qt.io/browse/QTBUG-10856
              Although the behaviour really is not bug and it is by design, but I think it is nessary and I hope QT to add a function for unlock temporary file to solve this problem in the future :)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ljc123456gogo
              hi you can easy get same clean up when you die function
              using smart pointers. So could make ur own tmp class pretty easy
              http://www.informit.com/articles/article.aspx?p=2085179

              1 Reply Last reply
              1

              • Login

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