QFileSystemModel/TreeView - issues
-
Hello there!
I'm experienced in C/C++, php.
Watched a lot of vids about QT, read 70% of 1 QT book.Important book part can not handle without your kind support:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileSystemModel>
MainWindow::MainWindow(QWidget *parent)
Creating a simple Qt Widgets application using the M/V pattern
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
ui->treeView->setModel(model);
ui->treeView->setRootIndex(
model->index(QDir::currentPath()));
ui->listView->setModel(model);
ui->listView->setRootIndex(
model->index(QDir::currentPath()));
}
Getting error aboveD:\prog\output1\output1\mainwindow.cpp:15: error: 'class Ui::MainWindow' has no member named 'treeView'
..\output1\mainwindow.cpp:15:9: error: 'class Ui::MainWindow' has no member named 'treeView'
15 | ui->treeView->setRootIndex(
| ^~~~~~~~ -
Just figured it out after your post...
Added, previous error solved, now having another errors:
:-1: error: release/main.o:main.cpp:(.text+0x55): undefined reference toMainWindow::~MainWindow()' :-1: error: release/moc_mainwindow.o:moc_mainwindow:(.rdata$_ZTV10MainWindow[_ZTV10MainWindow]+0x28): undefined reference to
MainWindow::~MainWindow()' -
@J-Hilk
Might be here in header?#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{
Q_OBJECTpublic:
MainWindow(QWidget *parent = nullptr);
~MainWindow();private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H -
As I posted mainwindow.h and mainwindow.cpp, there is only last available option - main.cpp
Seems ok for me, but still in QT for 130 hours, still lacking a lot of basic syntax..Please give me the lead, folks :D
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
} -
@jacob-n said in QFileSystemModel/TreeView - issues:
Seems ok for me, but still in QT for 130 hours, still lacking a lot of basic syntax..
You said earlier "I'm experienced in C/C++, php.". This issue has nothing to do with Qt, or its syntax (which it does not have as it is not a language). It is just standard, basic C++.
As I posted mainwindow.h and mainwindow.cpp, there is only last available option - main.cpp
No this has nothing to do with
main.cpp
.In your first post you showed the body of
mainwindow.cpp
. Where does that provide the definition forMainWindow::~MainWindow()
? -
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
QStandardItemModel
with it and theQTableView
will 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
-
@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.