Page 1 of 3 123 LastLast
Results 1 to 20 of 46

Thread: How to work with files

  1. #1
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Unhappy How to work with files

    I am newbie to Qt. So I would like to ask how create the app that would display (indx) the file system (or some directory). Then it should write this file to XML (with name, size etc). This app should also has capability to search for file. So I want to one how to create such application, what components of Qt I should use, where I can refere for similar examples, especially for this 3 issues and creating such interface. How much work it needs and how many files I should create?

  2. #2
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to work with files

    Sounds like homework. What have you done so far?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,018
    Thanks
    280
    Thanked 816 Times in 805 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to work with files

    Sounds like homework.
    No! Someone wouldn't actually post a homework problem here and expect us to feed them the solution, would they?

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

    Default Re: How to work with files

    I don't think they would. Everybody knows rules of this forum forbid to post solutions to homework.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    Really I can do it at home, at library. But it is not the homework, but the presupposition for the potential employment. But I am familiar with C++ just theoretically, and now I need to write this app even in unnnown for me, Qt (now I just try to free the space for Qt installation). So I would like to have some help here -- at least theoretically. How much files (.cpp, .ui, .h) I should create here, what components for the UI I need use, and how they should be connected with the code itself. What IDE I need- f.e. Codeblocks or Qtcreator. And the main--how to index the file system in the whole or locally (in some directory), how transfer this file description to xml, and search it (by name probably)? So I do not ask to do it for me, but theoretically as far as possible to explain and refer to most appropriate similar code --as I have just few days for it and it is very important for me.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to work with files

    But I am familiar with C++ just theoretically
    Sorry, but I think it will be almost impossible to use Qt if you don't have any practical experience with C++.

    Anyway, as for the IDE, I'd choose QtCreator.
    First I'd try to get familiar with Qt by studying some simple examples, you will have plenty of them in your Qt installation folder.
    As for your main task, here are some useful classes: QDir, QFileInfo, QFileDialog, QFileSystemModel, QXmlStreamWriter.
    Regarding the ui, I'd start with something very simple, like having just single button to browse for existing folder and tree view to display the folder contents, and then you can build more complicated functionality based on that.

  7. #7
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    http://het.as.utexas.edu/HET/O_M/Ope...-filetree.html -- Can such files be some patterns for the app structure? Or this-- http://doc.qt.digia.com/qt-5.2/qtxml...e-example.html -- for the displaying file system? I think the indxing should be done in some simple way or it need some particular file? Then I need QXml probably with QFileInfo function. And as far as I know it superficially the search should be done by Xqueries as I did not found any information on search in qt files.Then I need the outlook of my UI -- probably the button for the indeexing, converting to xml, and the field for the search and field for the results for thee tasks (at least for the last one). Then the structure of app is also important except the code itself as I was tasked that such app should be relatively easy in Qt?

  8. #8
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    Any suggestions? Would show any framework for this app, at list nessesary functions, then I would handle it be myself?

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,018
    Thanks
    280
    Thanked 816 Times in 805 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to work with files

    Your Qt installation comes with a whole slew of examples. Look at the DirView, File System, and maybe the XML Schema Validation examples. There is a Getting Started with Qt Widget tutorial, also installed with your Qt distro.

  10. #10
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    But what the indexing of file system means -- how I should do it exactly? Should I do some DB of all files of disk or directory -- or directory files should be dislayed in some UI window with some files pictograms as usual windows?
    And I have recently seen that search aslo could be done by QFileInfo, despite it has such attributes as size, path of files.
    What main fuctions I should use: funct1 (Q...1), func2 (Q..2) XML, func3 (Q..2) search?
    If I use Qcreator -- how connect it with the code? And the important questions is shoudl I use a lot of signals or slots as this constructions is new for me?
    So the first task--hwo to index the file system ...then it would be more understandable for me as to do evrything else

  11. #11
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to work with files

    What main fuctions I should use: funct1 (Q...1), func2 (Q..2) XML, func3 (Q..2) search?
    If I use Qcreator -- how connect it with the code? And the important questions is shoudl I use a lot of signals or slots as this constructions is new for me?
    With your lack of experience in Qt I suggest you to start with something basic, like selecting a file and displaying its stats (name, size, creation date etc) in a simple widget. You know, "Rome was not built in a day."

  12. #12
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    So what is indxing? If I need to use such attribute as path then I should present all the files (It is something like QSystemModel with List or TreeView?). And I do not understand what to "write file to xml" -- the content or its name., path etc? If in aforementioned tutorial there is xml widget.ui, so I understand that these ones should written as some property with these attributes in one list(file). So I need some input for the name of file system or the selector of disk C,D,F at the beginning.
    As the result the simple examples are in books and tutorials but I need to know the concept of the application with the main qt parts. For example you mentioned the Qtdesigner but it does not have no code extractor so what is the sense of it. And another issue -- does Qt have no exception hadling, as it do very complex the applications? For example during the inputing the disk name or file for the search that is so important in java.


    Added after 25 minutes:


    So what is indxing? If I need to use such attribute as path then I should present all the files (It is something like QSystemModel with List or TreeView?). And I do not understand what to "write file to xml" -- the content or its name., path etc? If in aforementioned tutorial there is xml widget.ui, so I understand that these ones should written as some property with these attributes in one list(file). So I need some input for the name of file system or the selector of disk C,D,F at the beginning.
    As the result the simple examples are in books and tutorials but I need to know the concept of the application with the main qt parts. For example you mentioned the Qtdesigner but it does not have no code extractor so what is the sense of it. And another issue -- does Qt have no exception hadling, as it do very complex the applications? For example during the inputing the disk name or file for the search that is so important in java.
    Last edited by artt; 24th March 2015 at 21:17.

  13. #13
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    Let it be. The Qt designer has the code viewer. But when I compile it the widget.ui transforms in widget.h. But How I can extract this last one--and what is difference between widget.h and widget.cpp.
    After the readinf several books on Qt development I undestand that I should use here the file listing that should be indexing.
    The finction Qdir that has ::disks method that view the content of disk then by use if (isdirectory) list this to the files, if it is the file show its attribute: name, size, path -- with Qfielinfo. So it should be like TreeView --that I should place in one window. So I should use the splitter for listed (indexed file). Then I should convert it in XML (probably DOM). But should I show the list of XML in particular window or just have the button--"write to xml"? Then I should use the search ability in XML (that is possible to some book) and display it in particular windows. So here I should have the textfield for entering the filename for search and label field for the dislaying the results. But should I convert the searched file from the xml to the list view. So here my more cleared vision of teh apps. The additional question is should I use the Q_Assert instead the exception handling?

    Why we need so detailed .h (and what to include) in addition to .cpp file, and how to convert the listed file system to xml is the main two issues just now for me?
    Is possible to use Qcreator for it?
    People I need your help as task is diffciult, but also too important for me.
    Last edited by artt; 25th March 2015 at 16:19.

  14. #14
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,018
    Thanks
    280
    Thanked 816 Times in 805 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to work with files

    The problem we have with what you're asking is that you know so little about C++ and Qt that we have nowhere to start. We can point you to example and tutorial code, but we can't write the code for you. And the questions you are asking are so unfocused that it is impossible to answer them. You're trying to run when you aren't far enough along to even crawl yet.

    As for what you write to XML - I am certain that the goal is not to write the contents of the files to XML. That's nearly impossible given the infinite variety of file contents and the fact that for most of them you have no idea how the content is formatted. Almost certainly, the requirement is to reproduce the hierarchy of the file system as XML. So you will need XML elements for "directory", "file" and maybe "symbolic link". For directories, you'll need attributes for number of files and directories contained within them. For all three, you'll need an attribute which describes the file system permissions attached to the object: read only, writable, executable, system, hidden, etc. and a creation / modified date attribute. For Files, you'll need to add file size, file type, and other attributes.

    To select the directory to get this started, use QFileDialog, and restrict it to look at directories only. Once you have a directory name, use QFileSystemModel and its setRootPath method to load it. Whether you choose to display the model on screen or not (use QTreeView if you do) isn't particularly relevant unless the problem calls for it. There is no Qt class that I am aware of that will traverse a QFileSystemModel so you can serialize it somewhere. QTreeView does this, but it will do that with any tree-structure QAbstractItemModel and has no clue what the model contents mean.

    You then need to write a class that takes this model, traverses the hierarchy and writes it to an XML document (use QXmlStreamWriter or QDomDocument and related classes). There is no XML schema that describes this - you'll have to design one - basically using the ideas I stated above. You'll use the QFileInfo provided by the QFileSystemModel for whatever index you're looking at to extract the information about the node in the file system tree.

    Good luck.

  15. #15
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    Thanks for clarification. The problem is that untill now I did not used Qcreator --maybe it could simplify significially this task?, as well as I am using Qt4 (CodeBlocks) that frequently emits the error -- such as QHBox is not supported or so. Really I did not written the real applications in C++, so I need to know main components and the potential size of application (how many strings about is also very interesting!). What about the last commnet I think that I need to show the file tree (list) to make visible that I indexed the file system. Then I should make pushbutton "write to XML" (I think this results also should be visible in some way, despite the files should be in a very big amount) -- But at this stage I would like to know how simply link the files properties (name, size) with the DOM-XML classes and functions. And the last task -- to search -- it also would be relevant to show how search the file name and display it correctly. In this vein I think that the parent classs QHBOX will be appropriate to use but it seems not supoported in Qt4.
    And of course the structure of app is also unknown for me -- could I use just .cpp file, if not what I should write in.h file?

  16. #16
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,531
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to work with files

    artt, You are trying to build a nuclear reactor without knowing the basics of physics and mathematics. Do You understand the allusion ?

  17. #17
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    You probably overestimate the issue for me. I ask here the algorithm not code. I see my task that I should make one window with button to index the files or select the drive. Near that button I see the display of file tree. But it is gui. But what I should use in Qt for the file description – the some structure (or list) with the fields of number, name, size, and path? Then it should be written in some file. Then I write this file to xml in some way where properties of every item should be (converted from) name, size, and path. Then I write xml to another file. Then I make the field for the search of file name and the sub-window for displaying the results (and code for the function that search the file name in properties of file). That is my vision – if I am grossly incorrect you can show it. I write it everything as it is very difficult for me but it determines in some way the further experience as programmer// If it is better to write such app in sharp or java, it could be the option. If it is possible to make a lot of things in qcreator (as it was said at the beginning) I would do it as now has the problem with the msvcp100.dll despite copied it to bin and system folder. And I do not understand why I cannot write private messages.


    Added after 7 minutes:


    You probably overestimate the issue for me. I ask here the algorithm not code. I see my task that I should make one window with button to index the files or select the drive. Near that button I see the display of file tree. But it is gui. But what I should use in Qt for the file description – the some structure (or list) with the fields of number, name, size, and path? Then it should be written in some file. Then I write this file to xml in some way where properties of every item should be (converted from) name, size, and path. Then I write xml to another file. Then I make the field for the search of file name and the sub-window for displaying the results (and code for the function that search the file name in properties of file). That is my vision – if I am grossly incorrect you can show it. I write it everything as it is very difficult for me but it determines in some way the further experience as programmer// If it is better to write such app in sharp or java, it could be the option. If it is possible to make a lot of things in qcreator (as it was said at the beginning) I would do it as now has the problem with the msvcp100.dll despite copied it to bin and system folder. And I do not understand why I cannot write private messages.
    Last edited by artt; 25th March 2015 at 20:26.

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

    Default Re: How to work with files

    Quote Originally Posted by artt View Post
    You probably overestimate the issue for me. I ask here the algorithm not code.
    The algorithm for what?

    I see my task that I should make one window with button to index the files or select the drive. Near that button I see the display of file tree. But it is gui. But what I should use in Qt for the file description – the some structure (or list) with the fields of number, name, size, and path?
    So... if you get the job and you get a task to do similar to this one, are you going to be asking at forums what data structures to use to solve that task?

    That is my vision – if I am grossly incorrect you can show it. I write it everything as it is very difficult for me but it determines in some way the further experience as programmer// If it is better to write such app in sharp or java, it could be the option. If it is possible to make a lot of things in qcreator (as it was said at the beginning) I would do it as now has the problem with the msvcp100.dll despite copied it to bin and system folder.
    The language doesn't matter. You can write the same program using asembly, C++, Python or whatever other general purpose programming language there is. I think the point of the task is to come up with a usable approach to indexing files. Whatever the author of the task meant by "indexing". Usually that means to generate a register allowing quick lookup in a large data set (just like an index in a book). I can also say there are many data structures useful for storing indexes. Which one to choose depends on a particular use-case and the underlying storage.

    And I do not understand why I cannot write private messages.
    I might be able to help you with that one if you tell me (e.g. using the Feedback forum) what error message you get or what else is wrong.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to work with files

    So what structures I should use for indexing? As I have read the Qt has a 400 classes and tenfold of function of it. What about private messages -- when I send it the lsit of send messages is left with 0 ones (empty). Maybe its is due to not very big time at forum or a few messages. And what about work -- this task is the supposition for potential employment and that would be the realization of my university study.

  20. #20
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to work with files

    As I wrote in the private message - please just start coding already. Show us that you have played around with examples, try to create something simple, something basic first and then move on to more complicated stuff.
    You keep asking about "linking the code to ui" - just open any example in :widgets: section in Qt installation, try to change the code, compile and test, observe the behaviour and draw conclusions.
    You can't solve this problem without getting your hands dirty.
    Leave the "indexing" issue aside for now, try to create a simple app to display the file stats in a widget. I think this is the best way to know new library or framework, by creating more and more complicated stuff from basic "building blocks".

Similar Threads

  1. Replies: 1
    Last Post: 14th April 2011, 09:58
  2. Replies: 1
    Last Post: 8th April 2011, 13:45
  3. Work with directory and files
    By amiref in forum Qt Programming
    Replies: 4
    Last Post: 24th March 2011, 09:26
  4. Replies: 4
    Last Post: 11th January 2011, 13:27
  5. Pack all .qm files into .qrc, why doesn't work???
    By yxmaomao in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2008, 19:38

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.