Unsolved General planning
-
Hello!
I have a few questions about a project im trying out. I have just started playing with different ideas on how to solve problems that i might have to deal with later on .
So the program im working on will eventually handle data TO and FROM databases.
The databases will be locally stored files of some type. The idea is to create a structure with the same output every time :)So my plan was to create an interface to work in where i could create a "project" a file to contain my information that i want to store, save it and start to fill it with information save it and close.
The next time i want to open it i want to select and open the file and the file would setup the UI and let me continue where i last saved it.
Everything in the file would be editable so that i can delete data and change data and save.Later on i might want to be able to export from the UI to other filetypes of some kind. Most probably *:xls
So i have never before been playing around with files so i gor some questions :)
When i first open the UI it will be empty of information but will give me predefined places where i will input specific data. As´long as i have NEW data in the input fields i just dont want the program to quit without me having a chance to be able to save the project as a new project :)
My idea was when ever NEW data was input in any of the input fields i would change a state BIT this would block the program from exiting without giving me the chance of saving.
Is this a good idea or would i have to solve it in another way?The same question would be for opening a file into the UI. The program has to know that a file has been opened. A bit tricky would be to compare the opened file to new data?
Since all the input fields would say that they contain new data as soon as data from the file has popped into them? The data could still be unchanged in comparison to the file so there would be reason to save ot really?I think that was it so far :)
-
Hi and welcome to the forums.
Its a normal use case to use a bool flag to tell if is data is dirty or not.
Qt has one already you can reuse
https://doc.qt.io/qt-5/qwidget.html#windowModified-prop
Or add your own to the data if needed.
So yes, its ok way to do it.When you write database you mean in a general way "collection of data" and not a real database system that Qt also supports?
https://doc.qt.io/qt-5/sql-programming.htmlAlso depending on your data types, please be aware that alMost all widgets and
Qt data types can be saved/loaded from QDataStream.
This can reduce the amount of code needed a lot.Also be aware of
https://doc.qt.io/qt-5/model-view-programming.htmlAs using models can make it much easier to share data between views of it.
You get many things for free.So what type of data do you need to load and modify ?
-
Thank you for a nice welcome and a good reply :)
To explain what i mean by "database" i mean a file rather than a system.
It has been a while since i used QT but what im trying to achive is a local management UI that can read data from database files and also create where i can save data in a pre-structured way.To interface with the database i have been looking at QTableWidget. So when i load a database it will end up in a table just as the DB is. When i save it it will go back into the DB.
I was a bit torn at first. I remember doing something with SQL testing and playing around with different querys on the server and im pretty sure i used QTableView back then.
Now im pretty sure i want to go with QTableWidget instead after reading the documentation yesterday.
Starting up a project i was going to use QLineEdit as UI all other data i create in the program with various widgets will go into the table then to the DB file.The data im going to load and modify is going to be short text, numbers and date (maybe).
Usage will be to designate component names .
Text for designation letters and numbers for specification and index.
So nothing complex really :) -
@TooHappy
Hi
TableView would work with the SQL models directly reading and editing the database tables.
Going with TableWidget you will manage most of that manually.
However, its also doable with tablewidget and if data is simple it will not be that involved. -
@mrjj
Ok, super!
Sounds like it will do something in the end :)
Now i will read up on info and start testing to see how things connect.Thanks!
-
Hello!
Got some questions :)
Some progress has been made! Its really hard to get going since it was 10 years since last time ive done anything in QT or programming ;)
When i launch the program wich is a GUI that pops up a mainwindow i want to check for drivers and ETC. Where would i place and call this function and what do i call to check? Would it be the window or the core?
What im after is a message that tells me something is wrong and i cannot proceed as normal.
This function could fire at startup and block functions that depend on the things it checks.Also want to keep track of changes in the program like IF there is a file open i wont be able to just close the program without get the chance to save the progress.
Also since im able to close the program from several locations. So several objects want to call one function seems to be a good way to go. I guess i could do it separate but i would get lost if i had to make changes in three functions instead of one.
So what i want is to create a function or a constructor in the mainwindow that takes care of this and i will call it with signals from several objects? -
@TooHappy said in General planning:
When i launch the program wich is a GUI that pops up a mainwindow i want to check for drivers and ETC. Where would i place and call this function and what do i call to check? Would it be the window or the core?
What im after is a message that tells me something is wrong and i cannot proceed as normal.Maybe something like
QSplashScreen
.
(Check the example, you can put anything you want there ofc)
https://doc.qt.io/qt-5/qsplashscreen.html#detailsIf you want to do something before your
MainWindow
shows up, you could put in in yourmain
function@TooHappy said in General planning:
Also since im able to close the program from several locations. So several objects want to call one function seems to be a good way to go.
Override
closeEvent
of your mainWindow and check whether there are unsaved changes or not. If there are any, you can ignore that event and make the user save the progress first. Your program keeps on running then.EDIT:
To track modifiations, you can use
windowModified
https://doc.qt.io/qt-5/qwidget.html#windowModified-prop -
@TooHappy
@Pl45m4 has given you some good suggestions. ThecloseEvent()
approach is shown in the code fragment below https://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html#mainwindow-class-implementation. That whole topic page is possibly worth looking through, it shows a number of useful things you might be interested in for your first skeleton main program. -
So far im running tests to se how i can use QSplashScreen. Other than looking cool its displaying events so thats good!
A down side is that there is not much to run through so the sceen just pops up and dissappears :P
I had to hijack the screen with a timer to delay it for a second.My general plan is to move some code from the main window to the main.cpp so if i get a fault or if im missing something the program needs i can choose to close or proceed. Even pop an error message if something is really bad.
Will look in to the other things when i get there :)
Is there a rule of thumbs on how to use qDebug?
What to print and what not in the case of logging to file?
Right now im just using it to read the output when i test to se if it goes wrong and where.