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. qt file search and open
Forum Updated to NodeBB v4.3 + New Features

qt file search and open

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 625 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.
  • S Offline
    S Offline
    s002wjh
    wrote on last edited by
    #1

    for Linux if I have file under /home/test/test.txt how would I search test.txt under /home/test and open it? using Qdir or Qfileinfo?

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

      Hi,

      Depending on your goal, using the find command through QProcess might be more efficient.

      Otherwise, using QDirIterator is likely more what you want.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        As @SGaist mentioned, there are a couple of ways of doing this and it depends on your goal. If it's simply to locate the file once then the QProcess route is probably adequate, although any spawned command process must be treated as a potential security risk and spawning subprocesses is a heavier weight solution. If you want to do it programmatically then you recursively call a method using elements of QDirIterator. This is comp-sci 101 stuff: recursive tree searches.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          s002wjh
          wrote on last edited by s002wjh
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            I am not sure I am following your question. QFileInfo returns information about a file so you can get what you want. Or are you thinking about some sort of filtering ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            0
            • SGaistS SGaist

              I am not sure I am following your question. QFileInfo returns information about a file so you can get what you want. Or are you thinking about some sort of filtering ?

              S Offline
              S Offline
              s002wjh
              wrote on last edited by
              #6

              @SGaist

              sry. i'm try to find certain file with extension. for example

              under c:/tmp I want to get the file name for any file with .txt extension. if there is no file with *.txt then return false, but if there is files with .txt I like to get that files info (name etc).

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Returning either false or a list of file names sounds fishy. You should rather handle the case of an empty list. It will be cleaner.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply
                1
                • SGaistS SGaist

                  Returning either false or a list of file names sounds fishy. You should rather handle the case of an empty list. It will be cleaner.

                  S Offline
                  S Offline
                  s002wjh
                  wrote on last edited by
                  #8

                  @SGaist

                  ok thanks, but i'm guessing use QDirIterator and Qfileinfo is the way to go?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    For your purpose, it looks like it yes.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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