QFileSystemModel/TreeView - issues
-
Here, constructor and desctructor
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
} -
Yeah, fixed that one. Thank you!
Can you please help with next issue, I found how to save data to kind of table and output.
Please advise alternative way to output data from array without saving into temporary table.
#include "Dialog.h"
#include "ui_Dialog.h"Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);model = new QStandardItemModel(5,2, this); ui->tableView->setModel(model); QModelIndex index; for (int row = 0; row < model->rowCount(); ++row) { for (int col = 0; col < model ->columnCount(); ++col) { index = model->index (row,col); model->setData(index,9); } }}
Dialog::~Dialog()
{
delete ui;
}Thanks in advance,
Jacob N -
Yeah, fixed that one. Thank you!
Can you please help with next issue, I found how to save data to kind of table and output.
Please advise alternative way to output data from array without saving into temporary table.
#include "Dialog.h"
#include "ui_Dialog.h"Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);model = new QStandardItemModel(5,2, this); ui->tableView->setModel(model); QModelIndex index; for (int row = 0; row < model->rowCount(); ++row) { for (int col = 0; col < model ->columnCount(); ++col) { index = model->index (row,col); model->setData(index,9); } }}
Dialog::~Dialog()
{
delete ui;
}Thanks in advance,
Jacob N@jacob-n
Your code just shows putting some data into the model. I don't know what you mean by "output data" and where a "temporary table" is involved.If you mean you don't need/want the data storage provided by a
QStandardItemModel, e.g. you have your own data in an array, look at QAbstractTableModel Class and the Subclassing section instead. All you have to do isWhen subclassing
QAbstractTableModel, you must implementrowCount(),columnCount(), anddata().Just tie those to your array.
Editable models need to implement
setData(), and implementflags()to return a value containingQt::ItemIsEditable.And implement
setData()to write into your array.Once you have that you can replace the
QStandardItemModelwith it and theQTableViewwill work the same but use your array as the model. -
Hello there!
qDebug() << ui->tableView->model()->index(0,0).data();
outputting to console this:
QVariant(int, 1)
I just need to return to function this int value.like
return ui->tableView->model()->index(0,0).data();
return tableView.getData(something);What is the proper syntax ?
BR
Jacob
-
Hello there!
qDebug() << ui->tableView->model()->index(0,0).data();
outputting to console this:
QVariant(int, 1)
I just need to return to function this int value.like
return ui->tableView->model()->index(0,0).data();
return tableView.getData(something);What is the proper syntax ?
BR
Jacob
@jacob-n said in QFileSystemModel/TreeView - issues:
I just need to return to function this int value
-
This post is deleted!
-
@jacob-n said in QFileSystemModel/TreeView - issues:
is there a way to convert from QVariant to std string?
Convert it to a QString and then to a std::string.
-
done! Thank you!
How do you guys make back up with QT?
If I just copy folder and trying to open project from new folder it will not build good.
Please advise@jacob-n said in QFileSystemModel/TreeView - issues:
How do you guys make back up with QT?
Using a proper code version system like Git.
"If I just copy folder and trying to open project from new folder it will not build good." - what exactly happens? You probably need to delete the *.pro.user file.