Unsolved Mixing QT with C++ Standard Library
-
Hi,
is it feasible to mix QT commands with Standard Library
commands?-
as far as I know QT Container are compatible with
std-<algorithm> and std-iterators. Is this correct?
Is this feasible? Does anybody use it?
Does one need special considerations? -
What std commands do you use in your QT code?
Can you provide examples?
e.g. std::sort() seems useful for me. -
Do you also mix std containers with QT container in one
project?
Thanks for help.
-
-
See https://doc.qt.io/qt-5/containers.html
I don't see a reason why it should not be mixed but you should not convert it the whole time. -
I am generally paranoid of mixing Qt containers with STL containers, but have no qualms about using STL for platform independent modules that need to exist within a Qt app. I just make sure to do explicit conversions if the behaviour documentation doesn't meet my standards. It usually does not.
-
@Kent-Dorfman said in Mixing QT with C++ Standard Library:
I am generally paranoid of mixing Qt containers with STL containers
Why's that? Have you experienced issues?
@TauCeti said in Mixing QT with C++ Standard Library:
is it feasible to mix QT commands with Standard Library
commands?Yes.
- as far as I know QT Container are compatible with
std-<algorithm> and std-iterators. Is this correct?
Is this feasible? Does anybody use it?
Does one need special considerations?
Yes. Yes. Yes. Yes.
For your last question, see the Implicitly Shared Iterator Problem: https://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
-
What std commands do you use in your QT code?
Can you provide examples?
e.g. std::sort() seems useful for me. -
Do you also mix std containers with QT container in one
project?
I quite happily do things like:
- Put QString in a
std::pair
- Put
std::shared_ptr<MyStruct>
inside a QVector - Use
std::sort()
,std::copy_if()
on my QVector
However, I avoid converting a Qt container to an STL container and vice-versa, like @Christian-Ehrlicher said.
- as far as I know QT Container are compatible with