General questions about Model in Qt (docs)
-
I have another bunch of questions. I don't want to start new topic of newbiesh questions so I decided to continue write here.
- DOCS:
"Model indexes contain a pointer to the model that created them, and this prevents confusion when working with more than one model".
QAbstractItemModel *model = index.model();
What does .model() means? It must be a member of
QAbstractItemModel
class but I can't find such memeber inQAbstractItemModel
class. Maybe it should beQAbstractItemModel *model = model.index();
But there is no member index() with no parameters. Also I can't see Model indexes in this example.
- Another question.
I always thought that in C++ pure virtual function is obligatory for implementation in child classes. To illustrate that I've created class A with
virtual void myFunction() = 0;
and class B : public A (class B inherits class A). So class A is abstract (you can't create object of such class). Class B is not abstract so I can create object of class B... BUT! Only if I implement virtual function
virtual void myFunction() = 0;
in class B first. Maybe not implement, but just write like that:
void myFunction() override {};
Even without implementation. Only after that I can create object of class B. So implementation of virtual function is obligatory for child classes.
But when I made subclass from
QAbstractItemModel
with 5 virtual functions (index()
,parent()
,rowCount()
,columnCount()
, anddata()
) my project was build even when I commentedindex()
,rowCount()
,columnCount()
which are virtual. Why if I must implement all virtual functions?-
If I press F2 to name of class (for example
QStringListModel
) I go to header file. But where is cpp-files to see the impementation of it? -
Also I'd like to find out what is Qt-class is? I mean
Qt::green
orQt::TextFormat
? When you typeQt::
you have huge list of autocomplite. Is this superglobal class?
@Xilit said in General questions about Model in Qt (docs):
- If I press F2 to name of class (for example QStringListModel) I go to header file. But where is cpp-files to see the impementation of it?
If you checked "Sources" during installation of Qt (in Qt installer) you should be able to go to the .cpp file after pressing F4.
But if you don't have Qt sources, then there is actually no .cpp file so Qt Creator cannot show it.
You can always look the file up, for example in Woboq code browser or by downloading Qt source code manually.
- Also I'd like to find out what is Qt-class is? I mean Qt::green or Qt::TextFormat? When you type Qt:: you have huge list of autocomplite. Is this superglobal class?
It's a namespace. See the docs.
- DOCS:
-
@Xilit said in General questions about Model in Qt (docs):
- If I press F2 to name of class (for example QStringListModel) I go to header file. But where is cpp-files to see the impementation of it?
If you checked "Sources" during installation of Qt (in Qt installer) you should be able to go to the .cpp file after pressing F4.
But if you don't have Qt sources, then there is actually no .cpp file so Qt Creator cannot show it.
You can always look the file up, for example in Woboq code browser or by downloading Qt source code manually.
- Also I'd like to find out what is Qt-class is? I mean Qt::green or Qt::TextFormat? When you type Qt:: you have huge list of autocomplite. Is this superglobal class?
It's a namespace. See the docs.
Thank you!
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my project
QAbstractItemModel *model;
, put cursor onQAbstractItemModel
and press F2 --> go to header (qabstractitemmodel.h
). And after pressing F4 nothing happened. Did I made something wrong?"It's a namespace. See the docs."
Got it. Thank you!
-
Thank you!
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my project
QAbstractItemModel *model;
, put cursor onQAbstractItemModel
and press F2 --> go to header (qabstractitemmodel.h
). And after pressing F4 nothing happened. Did I made something wrong?"It's a namespace. See the docs."
Got it. Thank you!
@Xilit said in General questions about Model in Qt (docs):
Thank you!
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my project
QAbstractItemModel *model;
, put cursor onQAbstractItemModel
and press F2 --> go to header (qabstractitemmodel.h
). And after pressing F4 nothing happened. Did I made something wrong?Perhaps it does not work nowadays. Last time I tried this was a long time ago.
"It's a namespace. See the docs."
Got it. Thank you!
-
@Xilit said in General questions about Model in Qt (docs):
Thank you!
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my project
QAbstractItemModel *model;
, put cursor onQAbstractItemModel
and press F2 --> go to header (qabstractitemmodel.h
). And after pressing F4 nothing happened. Did I made something wrong?Perhaps it does not work nowadays. Last time I tried this was a long time ago.
"It's a namespace. See the docs."
Got it. Thank you!
-
Thank you!
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my project
QAbstractItemModel *model;
, put cursor onQAbstractItemModel
and press F2 --> go to header (qabstractitemmodel.h
). And after pressing F4 nothing happened. Did I made something wrong?"It's a namespace. See the docs."
Got it. Thank you!
@Xilit said in General questions about Model in Qt (docs):
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my projectQAbstractItemModel *model;, put cursor on QAbstractItemModel and press F2 --> go to header (qabstractitemmodel.h). And after pressing F4 nothing happened. Did I made something wrong?
I'm pretty sure, you have to add the path manually in the settings of QtCreator.
Settings -> Debugger -> General -> Add QtSources -
@Xilit said in General questions about Model in Qt (docs):
That's strange. I've checked "Sources" during installation of Qt but after pressing F4 nothing happend. For exmple I created in my projectQAbstractItemModel *model;, put cursor on QAbstractItemModel and press F2 --> go to header (qabstractitemmodel.h). And after pressing F4 nothing happened. Did I made something wrong?
I'm pretty sure, you have to add the path manually in the settings of QtCreator.
Settings -> Debugger -> General -> Add QtSources -
@Xilit More or less, on the right side you can click on
Add Qt sources
that opens a QFileDialog, where you select the QtSource folder you downloaded.
After accepting, QtC should set up everything on its own!@J-Hilk
Still don't work.( But as I've mentioned above I've already found in Woboq code browser. On this link).
Interesting. I download
Sources
to make MySQL work, but it doesn't. Maybe that's why? Because Sqlite does. But I'm not sure what doesTarget path
means. -
@J-Hilk
Still don't work.( But as I've mentioned above I've already found in Woboq code browser. On this link).
Interesting. I download
Sources
to make MySQL work, but it doesn't. Maybe that's why? Because Sqlite does. But I'm not sure what doesTarget path
means.