Adding items to tableView QT - c++

i need i little help here. I'm creating a application through QtCreator (C++). It's basically a single view application that the user input two line edits, click return than the data from both fields goes to a table view. Here is my problem, i have no idea how to make it work (show the data typed and update the tableView every time the user presses return, i never used tableView before (QT)). I'm not even using database, it's not necessary. And i'm saving the data in a struct.
Any help?
Sorry about my english, thanks in advance!!!!!

Related

Oracle apex form doesent INSERT/UPDATE or Create entry in database

Hi everyone so I have a problem with Oracle Apex, I created a master-detail with a from and everything worked fine. Then I created another page within the same app but nothing connected to the page mentioned before, and now nothing on the first page works. When I try to create an entry the form opens I can type anything in and when I click "create" the form closes and nothing happens. Nothing is inserted into the database, edit also doesn't work as well ass deletes everything looks perfect till the form closes, the region refreshes but nothing actually happens.
No error shows up in the app or in the console/debugger
I checked the form processes and the DML is there.
Tried to manually set value in SQL Workshop and that works, I'm able to manually insert rows but not through the form.
Please help this is for my final project and I need this to work.
Thank you in advance!
Edit: 4) Also saw that no button works on the form. I have a combination of form + interactive grid and the grid usualy has like a page navigation buttons for previous/ next and those dont work aswell. So maybe i try deleting and re creating all the buttons?
EDIT2: Managed to fix it, and found that I was somehow missing the Close Dialog process in my form. Added it and now everything works!
Close dialog process in the form page was missing, recreated it from a different form, and now everything works!

QTableView displays column headers, but no data?

I can't figure out why my QTableView won't display any data. I've searched all other questions about this problem and it seems the problem is usually someone trying to create the model on the stack and letting it go out of scope...
I am creating the model on the heap so this is not the problem, yet I still get no data in the View. The column headers from my sql table are shown correctly. What could be wrong with this code?
// db is my database wrapper and database returns a reference to the database
QSqlTableModel *tradeHistoryModel = new QSqlTableModel(this, db->database());
// table_tradeHistory is my QTableView created elsewhere
table_tradeHistory->setModel(tradeHistoryModel);
tradeHistoryModel->setTable("mytrades");
tradeHistoryModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (!tradeHistoryModel->select())
{
// err is just a handy macro for displaying fancy error output
// the call to select does NOT return false so this never gets called
err("model select failed!");
}
// debug is another macro, the output shows 200 rows (which is correct)
debug(QString("Got %1 rows..").arg(tradeHistoryModel->rowCount()));
So there is no error shown because select() returns true, and the debug output shows the model selected all 200 rows, but still no data appears in the View...
Thanks for any help!
Edit: This must have been a Qt or Qt Designer bug... I went back into designer and "morphed" the QTableView into a QTreeView, then switched it back and now all of a sudden it is showing the data... I did not change any of the code when I did this... wtf? If it is a bug I'm not sure I can reproduce it again...
The problem might be the tradeHistoryModel->select(). I don't
think it is selected properly. Try to call it separately, not on a IF statement. Also check the compatibility of the data, the data on the db and that on the QTableView. I had a similar problem with QDate and I managed to solve it after modifying the format it was displayed on the QTableView. The problem was PostgreSQL and Qt uses different date format.
To be sure it has nothing to do with this problem try
model->setFilter(filter);
model->select();
or
modelsql->removeColumn(0);
to remove a column that might contain this problem. Good luck!
Thanks for the post. The same thing happened to me, and morphing the QTableView into a QTreeView and then back to a QTableView also fixed it for me. When I compared before and after, the original bad ui had the section <attribute name="verticalHeaderDefaultSectionSize"><number>0</number></attribute>. Maybe that made the header expand to the entire space of the view, and with no space to show rows of data, Qt had no reason to request data from the model.
I started with a QTableWidget but later switched to a QTableView to implement batching through canFetchMore/fetchMore, so maybe this problem is something left over from the QTableWidget.

Save the current position/order in a QTabWidget when a button is clicked - User Settings

Is it possible to save the current tab position/order in a QTabWidget in Qt?
What I want is basically to be able to let the users arrange the tabs as they like and then let them save the position so when they open the application again the tabs are where they were when last saved.
In the past I have done this put this only saves the window geometry.
QSettings mySettings("someName", "MyApp");
mySettings.beginGroup("MainWindow");
mySettings.setValue("geometry", saveGeometry());
mySettings.endGroup()
;
Any idea how or where can I find the information to get this done?
Thanks
Apparently there is no built-in way to do it, so you need to implement it. I don't see any possible troubles with it.
For example, you may obtain the index of each widget using QTabWidget::indexOf, or you may iterate over all tabs and obtain widgets using QTabWidget::widget, depending on which way is more convenient in your app.
When starting the app, sort your widgets by saved index and add them to the tab widget in that order.

QDataWidgetMapper only updates first index to QSqlRelationalTableModel

I have a problem regarding parts of the QT framework. I am using QT 5.0.2 and am developing on Windows at the moment.
In my application I have a Tableview set up with a QSqlRelationalTableModel. Next to it I have a text field and 3 combo boxes connected to the relational table model. The widgets are mapped to the model using QDataWidgetMapper as follows:
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->addMapping(ui->courseComboBox, model->fieldIndex("course_shortcode"));
mapper->addMapping(ui->subjectComboBox, model->fieldIndex("subject_name"));
mapper->addMapping(ui->lecturerComboBox, model->fieldIndex("lecturer_name"));
mapper->addMapping(ui->themesTextEdit, model->fieldIndex("event_themes"));
As you see the SubmitPolicy is set to manual submit. Under the widgets i have a buttonbox containing a save and a reset button.
When the save button gets clicked, I do this:
qDebug() << this->mapper->submit();
qDebug() << model->lastError().text();
This will create the following output:
true
" "
Which means the submit was successful and there was no error reported.
Nevertheless only the first field gets updated in the model. All the other widgets reset their value to the value from the original model (because the model emits datachanged, which the mapper connected itself to, I guess).
I tried removing one or 2 of the mappings and always onl the field whichs mapping gets added first will be updated.
If I change the submitPolicy to autoSubmit the mapper does its work as intended. But I really need to have those reset and apply buttons and not have the data get submitted on change.
This seems like an occurrence of QTBug 1086 but that bug got fixed and I cant reproduce the problem from the bug report from the code there either.
I hope you can help me.
I edited my answer because I misunderstood the documentation and, after receiving a good explanation, I finally got the correct way to obtain the desired result.
You should simply modify the model edit strategy using QSqlTableModel::setEditStrategy() and change it to QSqlTableModel::OnRowChange.
This is needed in order to avoid the modifications to be sent to the underlying DB after every single column modification, something that would produce an update of the mapped widgets contents after the very first column change.

Saving user's data for my application part 2

My first question was: should I use dom, sax, or sqlite to save the data the user is inputting into my application. The answer I am going with is to use DOM.
My second question is: How should I load the contents of the file into the application when the user decides to open the file? Should it go through the whole file and distribute all the data to the correct spots in the GUI once the user clicks "open" on the file? Or should it only open the stuff up as the user clicks on certain areas?
My third question is: How does qt handle knowing when things have changed? How would i know when the user has changed something and ask them to save the file?
If you do not understand, please let me know and I will try to explain again.
Example:
I am not only reading gui locations.
But the contents of those. For
instance. The user is able to create
tabs that contain edit text boxes. And
those tabs are associated with items
that are in a list. When the user
clicks on an item in the list the user
will be presented with a whole set of
new tabs. And each tab has some
editing forms. The file will need to
contain what is in the list, what tabs
the user has created under each item
in that list and the contents of each
tab associated with the tab of each
item in the list.
Sorry that I posted another question that is similar to my last, but the other question was answered and now I need a new post.
Question 2: This very much depends on how much data you're dealing with. It will be much easier to load everything in one step. If you are expecting complex documents, it might be better to do it incrementally, but I would strongly recommend starting with the simpler approach.
Question 3: Qt does not handle this, except in as far as widgets will fire signals when they are modified. You need to do it, using a model of some sort. You could just use the DOM document directly as the model, although it may help maintainability to abstract the save format. Each change the user makes would cause a change in the model. You will need to detect when e.g. the user edits some text, update your model appropriately and keep track of whether it has changed since the last save.
What do you want to achieve with your solution? If you want to simply set Configuration why not using a simple Ini file (QSettings Class).
I don't know your application, but you should be able to recognise changes (lets say, if the user changed a QLineEdit or hit a radioButton).
There would be also a "sync" method for QSettings, which "rereads" the file you are working with. Qt won't recognise changes itself, you have to do that on your own.