如何从qt 6.3.0 c++代码
使用QT 6.3.0 QVECTOR
不再具有fromstdvector
方法。我不完全理解将std :: vector复制到qVector 并且想知道如何修改下面的treewidgetController :: getReponses方法。
特别是建议这些模板:
std::vector<T> stdVec;
QVector<T> qVec = QVector<T>(stdVec.begin(), stdVec.end());
foreach
被引用 qt foreach loop订购与Qlist的循环和此处 https://doc-snapshots.qt.io/qt6-dev/foreach-keyword.html
我不清楚的区域是: 响应PTR可以替换t,但是如何处理新的响应Interem
?
// This is a sample of the code, I would like to upgrade
void TreeWidgetController::getResponses()
{
// First remove all possible previous children.
removeAllChildren(_rootResponses);
// Retrieve the list of available responses.
vector<ResponsePtr> responses = dbSubsystem().getResponses();
// Create a new ResponseItem for every response.
foreach (ResponsePtr r, QVector<ResponsePtr>::fromStdVector(responses))
new ResponseItem(_rootResponses, r);
}
With Qt 6.3.0 QVector
no longer has fromStdVector
method. I didn't fully understand the answers in copying a std::vector to a qvector and would like to know how to modify the TreeWidgetController::getReponses method below.
In particular these templates were suggested:
std::vector<T> stdVec;
QVector<T> qVec = QVector<T>(stdVec.begin(), stdVec.end());
foreach
is referenced Qt foreach loop ordering vs. for loop for QList and here https://doc-snapshots.qt.io/qt6-dev/foreach-keyword.html
The area I am unclear about is:
ResponsePtr could replace T but how would the new ResponseItem
be handled?
// This is a sample of the code, I would like to upgrade
void TreeWidgetController::getResponses()
{
// First remove all possible previous children.
removeAllChildren(_rootResponses);
// Retrieve the list of available responses.
vector<ResponsePtr> responses = dbSubsystem().getResponses();
// Create a new ResponseItem for every response.
foreach (ResponsePtr r, QVector<ResponsePtr>::fromStdVector(responses))
new ResponseItem(_rootResponses, r);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需在此处重新发明轮子,只需查看
frofStdVector()
方法,该方法qcorelib/tools/qvector.h
在qt的早期版本中:您可以逐字将该功能逐字包含在您自己的标题之一中,然后将代码保持不变,也可以将其用作如何修改代码的示例。
There's no need to re-invent the wheel here, just have a look at the
fromStdVector()
method that is inqcorelib/tools/qvector.h
in earlier versions of Qt:You can either include that function verbatim in one of your own headers and leave your code unchanged, or use it as an example of how you can modify your code.