error: "'QObject::QObject(const QObject&)' is private" and "use of deleted function 'QObject::QObject(const QObject&)'"
-
You should override
roleNames
method in your model:QHash<int, QByteArray> PlaylistModel::roleNames() const { static QHash<int, QByteArray>* ret = nullptr; if (ret) return *ret; ret = new QHash<int, QByteArray>(); (*ret)[TitleRole] = "title"; ... return *ret; }
Then in QML you can use them as model property:
model.title
.@intruderexcluder yes, I overrided it. When I use
PlaylistModel
as a model in QML, I actually just want to accessm_data
variable, not all of PlaylistModel attributes.
Any suggestions to do that? Thanks a lot -
You are probably doing something wrong, but you can at any time simply add slot or invokable method to access any data.
-
@lucas_1603 said in error: "'QObject::QObject(const QObject&)' is private" and "use of deleted function 'QObject::QObject(const QObject&)'":
Yes, it compiled
...
I actually just want to accessm_data
variable, not all of PlaylistModel attributes.Is Song still a subclass of QObject?
-
@lucas_1603 said in error: "'QObject::QObject(const QObject&)' is private" and "use of deleted function 'QObject::QObject(const QObject&)'":
Yes, it compiled
...
I actually just want to accessm_data
variable, not all of PlaylistModel attributes.Is Song still a subclass of QObject?
@jksh No, it's not now. I think I'm doing right way in this time ^^
The challenge now is accessing tom_data
to get title, singer, source, album_art. -
@jksh No, it's not now. I think I'm doing right way in this time ^^
The challenge now is accessing tom_data
to get title, singer, source, album_art.@lucas_1603 said in error: "'QObject::QObject(const QObject&)' is private" and "use of deleted function 'QObject::QObject(const QObject&)'":
I think I'm doing right way in this time ^^
There's often more than 1 way to achieve something; some are just easier or more efficient than others :)
The challenge now is accessing to
m_data
to get title, singer, source, album_art.I see that you've implemented a Model. The idea behind a model is that you shouldn't need to access the internal data structure directly. Instead, you use the model's standard interface (rows, columns, and maybe roles) to access individual fields.
In your example, you can treat each Row as an individual song. You can also treat each Column as a song field (e.g. Col 1 = Title, Col 2 = Singer, etc.). Older examples use Roles instead of Columns
In QML, you normally don't call
data()
andsetData()
directly; you let the View and Delegate call them for you.Spend some time getting to know the model-view framework first:
- https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html
- https://doc.qt.io/qt-5/qtquick-models-objectlistmodel-example.html
This is quite a lengthy topic, so it's not something that we can teach you over a few forum posts. You need to spend time going through examples and modifying them to see how they behave. trying things out.
-
@lucas_1603 said in error: "'QObject::QObject(const QObject&)' is private" and "use of deleted function 'QObject::QObject(const QObject&)'":
I think I'm doing right way in this time ^^
There's often more than 1 way to achieve something; some are just easier or more efficient than others :)
The challenge now is accessing to
m_data
to get title, singer, source, album_art.I see that you've implemented a Model. The idea behind a model is that you shouldn't need to access the internal data structure directly. Instead, you use the model's standard interface (rows, columns, and maybe roles) to access individual fields.
In your example, you can treat each Row as an individual song. You can also treat each Column as a song field (e.g. Col 1 = Title, Col 2 = Singer, etc.). Older examples use Roles instead of Columns
In QML, you normally don't call
data()
andsetData()
directly; you let the View and Delegate call them for you.Spend some time getting to know the model-view framework first:
- https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html
- https://doc.qt.io/qt-5/qtquick-models-objectlistmodel-example.html
This is quite a lengthy topic, so it's not something that we can teach you over a few forum posts. You need to spend time going through examples and modifying them to see how they behave. trying things out.
@jksh Thank you so much
All you guys helped me a lot and I really appreciate it.
I'll spend more time to learn more about model-view framework to see how really they work.