Solved Tuple in Qt. How?
-
Is there any Qt native solution for using tuple?
-
Hi,
What exactly are you looking for ? Tuple is a C++ container, Qt is a C++ framework, you can just use it.
-
@SGaist I am seeking anything that is native for Qt, something like QTuple if it existed. I know about plain C++ Tuple functionality.
-
@bogong said in Tuple in Qt. How?:
@SGaist I am seeking anything that is native for Qt, something like QTuple if it existed. I know about plain C++ Tuple functionality.
There is QPair which has some functionality from tuple, but IMO it's better to use a custom
struct
. -
-
@sierdzio There are few things:
- QPair is only for pair
- I am seeking something that has kind of functionality for converting tuple to list (for example or something else)
- Struct - is Ok, but what if I want to get another tuple from origin tuple within added element dynamically in runtime???
In Erlang huge functionality for it. I though it might be presented in Qt.
-
@bogong said in Tuple in Qt. How?:
Struct - is Ok, but what if I want to get another tuple from origin tuple within added element dynamically in runtime???
to be completely type and platform independent you can use QVariantMap (depending how you want to use it in your code you might need to implement conversion methods)
-
@raven-worx Thx ... I know it and published example based on QHash already. But QHash or QMap not tuple itself. The question was especially about tuple itself.
-
@bogong said in Tuple in Qt. How?:
Struct - is Ok, but what if I want to get another tuple from origin tuple within added element dynamically in runtime???
You can't. C++ is statically typed, you can't change the type itself at runtime. The tuple is compiled-in as it appears at compile-time, can't be changed at runtime.
-
@bogong said in Tuple in Qt. How?:
I am seeking anything that is native for Qt, something like QTuple if it existed. I know about plain C++ Tuple functionality.
What functionality do you want in QTuple? Why don't you want to use
std::tuple
?I am seeking something that has kind of functionality for converting tuple to list (for example or something else)
Write a small function to convert the tuple (or struct) to a vector.
- Struct - is Ok, but what if I want to get another tuple from origin tuple within added element dynamically in runtime???
In Erlang huge functionality for it.
Erlang tuples don't allow you to add elements dynamically at runtime either.
I though it might be presented in Qt.
You can use
std::tuple
in Qt. It behaves just like the Erlang tuple. -
@JKSH My apology but you writing about what you do not know:
- Erlang tuples don't allow you to add elements dynamically at runtime either. - Really??? How about list_to_tuple function that is part of Erlang core??? How about turning matrix of tuples that been developed by me and published and here official documentation??? Erlang allow to create any tuple you want dynamically through list-conversion, there no need to define any tuple structure before tuple itself. All of it doing dynamically. The tuple in Erlang statical structure itself (like in C++) but it might be created in runtime dynamically without any definitions and I've been experimenting in plain C realisation based on char of elements that looks like tuple in operation. All of it based on Erlang sources.
- You can use std::tuple in Qt. It behaves just like the Erlang tuple. - I can't to do even something similar in case of your description and C++ documentation, that is why I've been asking about it (I thought I do not know something in QT only in Qt, I've been asking about ability of Qt manipulate tuples).
- Write a small function to convert the tuple (or struct) to a vector. - Why if I need to manipulate tuple itself and it's mentioned in my messages and the question was about it? Or convert something to tuple of random structure?
- You can use std::tuple in Qt. It behaves just like the Erlang tuple. - it's totally not. This data-structure manipulation functionality is the key-feature of Erlang, that's why it's so fast and lightweight.
It's funny that your wrong reply got upvotes 5 times ...
-
@bogong said in Tuple in Qt. How?:
It's funny that your wrong reply got upvotes 5 times ...
Perhaps the upvotes refer to C++ bits which we can verify. I upvoted because I agree with @JKSH on the C++ part of his answer. I don't know Erlang so I just ignored that part.
-
@bogong said in Tuple in Qt. How?:
@JKSH Erlang tuples don't allow you to add elements dynamically at runtime either. - Really??? How about list_to_tuple??? How about turning matrix of tuples that been developed by me and published
From the documentation of Erlang Tuple (emphasis added by me):
A tuple is a compound data type with a fixed number of terms.
As for list_to_tuple:
This method is to convert a list to a tuple
This doesn't allow you to add new items to a tuple, it allows you to create a tuple from a list.
-
Can
std::tie
be something like what you want (example: http://cpp.sh/4ifyc)?You can't, however, convert a generic vector to a tuple at runtime as tuple needs to know its size at compile time.
-
@VRonin The question was about QT but NOT std ... But it's partly similar functionality. Similar - because there are no any functionality to create random tuple in runtime. I've been seeking something that is allowing me to use tuple like base-type for messages between Qt application modules. I am trying to define data-type standard for message exchange in my Qt Applications and testing different data type and see what is better to use in my own case.
-
@SGaist Could you be pleased to get real experience in Erlang before copy-pasting docs that is not in context ... And AGAIN - the question was about QT but not Erlang, not std ...
-
Issue closed ... Only @sierdzio, @raven-worx and @kshegunov written something that is related to topic. Appreciate it. Thx.
-
Indeed, I should have also mentioned erlang::append_element which returns a new longer tuple based on the term you wanted to add to the original tuple.
-
@bogong Apologies, I used
std::tuple
in my example but I was referring more of a tuple as an abstract concept more than anything else.Given your use needs, why wouldn't
QVariantList
be suitable? -
@VRonin Because it's super SLOW!!! I've tested it already. In case of huge data exchanging "anti-idiot" guard that is implemented in QVarianList is slowing down this structure itself. The second point - it's dynamical structure itself. Any dynamical always much slower than any statical, that is why I've been seeking something that will allow me to create statical structure dynamically in runtime and use it in any part of application. If data not changed through whole life-circle why would I store it in dynamical manner?
BTW - for me, after huge experience of mixing Objective-C in Qt/QML. The data exchange model that is using in Qt - THE BOTTLENECK in any performance issue of Qt. Sometimes I need to convert 3-5 times one piece of data only for being able to use it in QML. But this is price for cross-platform and I understand it.