Important: Please read the Qt Code of Conduct -

Adding history and bookmarks to browser

  • Hello everyone,

    I have reached a point in developing my browser where I would like to add history and bookmark functionality.
    I would like the URL of the webpage to be written into a text file, the first ten entries in this text file would be created as QActions that will automatically appear under the 'history' menu. I basically need my browser to read and write to a text file. I also would like to have a 'clear history' QAction that deletes all the contents of the text file.
    How can I make my browser save every web page I visit as an entry in a text file, and also create the first 10 entries as QActions that take me to that entries URL?
    I figure that once I have this method of doing the history down, I can do something similar to make bookmarks.

    Example code would be great!

    Thank you!

  • I am puzzled why a text file particularly? It seems to me that while the browser is running you would want to keep your history in memory, as a list (QLinkedList?) or array. And then when you are closing down you can write the current history into the settings, and when starting up, retrieve the history list from the settings. QSettings provides for reading and writing "arrays" of similar items, which would be very handy for a list of QUrls, I would think.

    Using settings removes many complications like "where did the user save the history file" and "suppose the history file was erased or renamed between sessions" etc.

  • Alright, I'm a newbie and I think your approach sounds better! How would I do it? Could you maybe provide some example code?
    Thanks a ton!

  • You are a "newbie" and you are writing a browser? Oooookayyyy... well it's a way to learn. As to example code, I don't write in C++ but rather Python. If you can read Python take a look at one pet project, which is kind of a browser also: "Cobro": and read the readme.

    In, scroll down to "line 1661": (holy crap that got to be a big program...) where the QSettings is initialized.

    At "line 1391": is where the main window recovers its window geometry from the settings. At line 1652 is where the main window saves its current geometry for next time.

    At "line 914": is where the list model loads itself from an array in settings. Just above it is the code to save the list contents back into settings at shutdown.

  • okay I understand what you did there, but I'm not sure how to implement that in Qt C++.

  • Same class names, same method names, same sequence of operations. If you can see about what it's doing, just look up anything that starts with Q in the Qt Assistant and go from there.

Log in to reply