Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise
-
@jsulm table is fine, could be any other output methods you could recommend
@DerReisende said in Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise:
@icebergenergy You don‘t need to use all of Qt if not wanted. But then you may have to restructure your code for reuse.
Based on your example, why doesn‘t
readFromDat
e.g. return a std::vector<DataObject> for the parsed classes? In there you could perform the account filtering or defer it to a later step. Then you would need to write two functions:- one for printing the data via std::cout
- another one which e.g. creates a Qt table model for presentation in a Qt TableView for the UI part.
In one of my applications I parse a several hundred MB csv file with an external parser library (c++20), do some BOOST magic and calculations on it and get a vector of objects at the end. This is the base for a tree view model.
99% of the code is std c++ until you have to interact with Qt obviously. But perfectly doable.Although I do admit that Qt sometimes would simplify my life if I would use it more often in the std c++ code…
first of all, im stuck with fstream and Qwidget. Is there any way to cooperate like this or I have to use Q stream operators only?
#include "mainwindow.h"
#include <QApplication >
#include <QLabel>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include "iesnc.h"
#include <iomanip>fstream masterStream ( "C:/Users/iceberg/Desktop/kocgun/march/iesnc/iesnc/master.dat", ios::in | ios::out | ios::binary );
fstream saveLoadDatabase ( "C:/Users/iceberg/Desktop/kocgun/march/iesnc/iesnc/databaseCopy.dat", ios::in | ios::out | ios::binary );int main(int argc, char *argv[])
{QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();
}
-
@icebergenergy said in Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise:
first of all, im stuck with fstream and Qwidget. Is there any way to cooperate like this or I have to use Q stream operators only?
What do you want to do with your data? Where to show or use it? It's always better to use the
Q...
stuff when interacting with your Qt GUI, since it will just work better. But doesn't mean plain C++ or some boost stuff won't work either.For example
QFile
orQDataStream
... It's not that complicated. -
@icebergenergy said in Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise:
first of all, im stuck with fstream and Qwidget
In addition to @Pl45m4. What do you want to do with
fstream
that has anything to do withQWidget
? Your code just shows twofstream
s initialised for output to the file paths, no more than that, what is "stuck"? -
Once again, I want to keep C++ syntax, and use QT for executing C++ functions.
What is good option to output binary files with QT?
Qlabel? -
@icebergenergy said in Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise:
I want to keep C++ syntax, and use QT for executing C++ functions.
You're aware that Qt is a C++ library? So your statement somehow doesn't make sense.
@JonB asked about your real problem - what's your task you're stuck in? What did you try? What do you want to achieve? -
I need to output DAT file lines to QT Window, all calculations in DAT files, output in GUI.
[1] Find Interface to output
[2] On button click - read from DAT file function
[3] Output Line By Line to GUI interface [1]Read with C++ syntax
Output to GUI with Q SyntaxI have system working without GUI, I need GUI, need be to implemented step by step.
Where Q syntax is MUST I will go deep dive and transit there, if not I will keep C++ syntax -
And what did you try so far? Where are your problems? There are a lot of examples on how to build a simple Qt GUI application out there.
-
I've tried QLabel, I think it will be fine.
But I need proper sample.
So I'm here for your kind advise.
Need to output 4 columns from DAT file
BRDima
-
@icebergenergy said in Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise:
But I need proper sample.
I gave you a link to a lot of samples. Start with a basic one to get some ideas on how it works, then try to add your functionality.
Noone will write the code for you here. -
@Christian-Ehrlicher said in Need to build QT GUI using my C++ code. I want to be more C++ and less QT. Please advise:
And what did you try so far? Where are your problems? There are a lot of examples on how to build a simple Qt GUI application out there.
Bro, I've researched your link, and found interesting QTableView as a future library.
What do you think of QTableView in regard to my case? -
@icebergenergy
It's not clear (to me at least) what is in your "DAT file", and what you want to output/appear in a GUI.If you have some kind of (text) file with lines and multiple "fields" per line, separated somehow --- ahh, I see,
100 Donald Trump 777
--- and you would like to display it as rows (for the lines) and columns (for the fields), then aQGridView
orQTableView
might be good choices.These two are both "visual" (hence the word "view" at the end). You have to provide the data you want them to show in a suitable form. In the case of a
QTableView
that needs a model for its data. The model holds rows & columns of data, the view is attached to the model and displays it.Have a look at QTableWidget. That is a
QTableView
(for viewing) plus an internal model (for the data) combined into one widget. Read the lines from your file, split into appropriate fields, put that data into theQTableWidget
as you go and it will display as rows & columns. -
I agree with @JonB. The decision if you want to use QTableWidget or QTableView mostly depends on how many lines you expect to display. The easy approach is to use a QTableWidget with
setItem()
.setItem
needs aQTableWidgetItem
and its constructor takes a string (QString, obviously). So you can do a loop over all your data, construct QTableWidgetItems and place them in the table widget.If you don't do that too often (i.e. data does not change) and if you don't have to many items, this approach will work just fine. Otherwise you'll need a
QTableView
(QTableWidget actually derives from it) together with a model. For the model you have to derive from the proper class and overwrite the method that will yield the data for a column/row pair. How you retrieve the data is again up to you (just use plain C++ without Qt for the retrieval). -
@SimonSchroeder
Agreed. I suggestedQTableWidget
rather thanQTreeView
for this OP as I think he is looking for a simple solution and this avoids him having to write a model himself for aQTreeView
.