Solved Table creation with ListView
-
Hello, i'm developping an API that allows to show received CAN Bus messages by my can driver systec.
I'm using QCanBus. My received messages are stocked on a QStringList and it contains the identifier, the length and the data. My problem is that i can't create a table using ListView. I'm working on qt 5.11 and using Qt quick control 2.
How can i create a table displaying my data with Listview? -
How do you separate data in different columns?
-
I prefer you build your own model on C++ side & expose the model to QML side. Use delegate to format your data. How to expose the model & view in list view ? Refer the GIT
-
[0_1546446844578_canbusqml.h](Uploading 100%) ![
I want to use a ListView . This image shows my QStringList content at one index. The first element represent the identifier of the CAN message,the second the lenght and third the payload of the message. I want to seperate each one of that elemeents in different columns. -
Should be something like: https://pastebin.com/Vetsi5z7
-
Do you need to QML listView or QTableView is enough ? As @VRonin suggested, you can just use the QTableView along with QStandardModel to display it. If you want to display in QML, suggest you to use your own custom model.
-
@dheerendra I can't use QTableView because i'm working with qt 5.11 and developping mobile apps. In 5.11 version QTableView is only available for Desktop apps.
-
-
You are using the QML. You need to write your own model in C++ side to expose the data to qml. Use either ListView or TableView to display the data.
-
@VRonin Thank you
I'll try to use Tableview with custom model. Can i have an idea of how to seperates my data in identifiers payload and length colums?
The second problems is that i'm returning a List of QCanBusFrame. This type of data can't be displayed easily -
Can i have an idea of how to seperates my data in identifiers payload and length colums?
@VRonin said in Table creation with ListView:
Should be something like: https://pastebin.com/Vetsi5z7
This type of data can't be displayed easily
https://wiki.qt.io/How_to_Use_a_Custom_Class_in_C%2B%2B_Model_and_QML_View
-
@VRonin Last question.
Where should I seperate my data into frames? In main file or in model file? -
It's really up to you.
I would create theQCanBusFrame
outside the model and then load it but it's really just a matter of flavour -
const QRegularExpression partsRegExp(R"^\s*(\S+)\s+[(\S+)]\s+(.+?)\s*$");
from your link, this line code generate an error in QT. It says: Invalid character ''.................... -
old compiler?
You can double all the\
and remove theR
at the beginning -
@VRonin Thank you.
I seperated my data successfuly
You can mark it resolved