How can we save user date to the QTreeWidgetItem?

yanj20 2010-04-08 04:25:53
In MFC for CTreeControl we have function call SetItemData to set the user
data to a tree items. Like that how can we set the user data to QTreeWidget
? . Can any one help me with the simple code snapshot ?
...全文
498 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Aisy_D 2010-04-08
  • 打赏
  • 举报
回复
the sample demo "interview" which locate at $QTDIR$\demos\interview\interview.exe is your friend, please take time to understand it....
yanj20 2010-04-08
  • 打赏
  • 举报
回复
struct JOB{
name;
id;
};

QStringList subfileList;
JOB *pJob = new JOB();; //user data struct
subfileList.append(pJob.name);

//here we save the user data to the var
QTreeWidgetItem *childItem = new QTreeWidgetItem(subfileList);
QVariant var(QVariant::UserType, pJob);
childItem->setData(0,Qt::UserRole,var);
parentItem->addChild(childItem); //here we add the childItem to the QTreeWidget

//here we try to get the data saved in var that connected to the Item
JOB *savedObj = (static_cast<JOB*>(var.data())); //???I couldn't get the values
yanj20 2010-04-08
  • 打赏
  • 举报
回复
thanks Aisy_D,so would you please show me the subparagraph code?
Aisy_D 2010-04-08
  • 打赏
  • 举报
回复
I will upload this demo's source-archive to somewhere and share the URL's link for everybody to download it.
Aisy_D 2010-04-08
  • 打赏
  • 举报
回复
Well, there are sure ways to add your extra customer data to your Qtreewidget.
one of the common approachs is that create your own class which inherits "QDataModel", i.e. QDirModel , and then reimplement public function "columnCount ( const QModelIndex & parent = QModelIndex() ) const" to set up extra columns for holding your custmoer data, and then reimplement two functions "data()" , "setData()" to showi or manuplate your own data, another function headerData() for modifying the showing text on the header row of Qtreewidget, I'v just got this cutomer data work in my demo "BatchRename" ,take a look at the screen snap followed:
dyw 2010-04-08
  • 打赏
  • 举报
回复
可以用setData方法设置任意的数据,除了用Qt::UserRole外,你还可以自己定义Role...
yanj20 2010-04-08
  • 打赏
  • 举报
回复
Thank you,I work on ubuntu linux,and i have try the setData function,but it didn't work.

Q_DECLARE_METATYPE(JOB*) //JOB is user defined data structure
QTreeWidget *pTree = new QTreeWidget();
JOB *pJob = new JOB();
QTreeWidgetItem* item = QTreeWidgetItem(pTree);
item->setText(0,"Test Text");
QVariant var;
qVariantSet(var,pJob);
item->setData(0,QAbstractItemModel::UserRole,var);

like the above method,application cann't save the pJob,Can any one help me with the simple code snapshot ?
Lutx 2010-04-08
  • 打赏
  • 举报
回复
setData(column, Qt::UserRole, yourdata);

bsr2009 2010-04-08
  • 打赏
  • 举报
回复
楼上的方法可以试一下.LZ的平台是用在哪里的?S60? CE?
pornographer 2010-04-08
  • 打赏
  • 举报
回复
看了下好像由函数的

先从qtreewidget 获得qtreewidgetitem的指针

然后用这函数
void QTreeWidgetItem::setData ( int column, int role, const QVariant & value )

这个具体我没用过 随便yy一下
内容概要:本文围绕“考虑光伏-储能-数据中心多能互补的园区容量优化配置”展开研究,提出了一种基于Matlab代码实现的优化模型,旨在通过整合光伏发电、储能系统与数据中心的高耗能及灵活负荷特性,实现园区内多能系统的高效互补与协同运行。研究建立了综合考虑可再生能源出力波动性、储能充放电特性和数据中心用电规律的数学模型,采用灰狼优化器(GWO)等智能算法求解最优容量配置方案,并可能结合CEEMDAN等信号分解技术进行功率平滑与波动抑制。通过多时间尺度协调与系统级优化设计,提升能源自给率、降低运行成本、增强新能源消纳能力,体现了综合能源系统规划中的先进建模范式。; 适合人群:具备一定电力系统、能源工程、自动化或相关专业背景的科研人员、研究生,以及从事综合能源系统、微电网、绿色数据中心、可再生能源集成等领域技术研发的工程师。; 使用场景及目标:①用于科研复现与学术研究,深入理解多能互补系统容量优化的建模方法、求解流程及关键约束处理;②为工业园区、数字经济园区、绿色数据中心等实际场景的能源系统规划提供技术支撑与决策依据,目标在于实现节能减排、提高能源利用效率与系统经济性;③作为Matlab仿真与智能优化算法应用的学习资源,掌握GWO、CEEMDAN等算法在能源系统优化中的集成与实践。; 阅读建议:建议结合文中提供的Matlab代码进行同步仿真验证,重点关注目标函数构建、约束条件设定、多变量耦合关系及算法收敛性分析,同时可参考文档中提及的混合储能功率分解、风电波动平抑等关联技术模块,深化对多能系统协同优化机制的理解。
内容概要:本文围绕“基于UKF与SRCKF的分布式驱动车辆状态联合估计研究”,系统探讨了利用无迹卡尔曼滤波(UKF)和平方根容积卡尔曼滤波(SRCKF)对分布式驱动车辆的关键运动状态参数(如横摆角速度、质心侧偏角、纵向/横向速度等)进行高精度联合估计的方法。研究通过构建基于Simulink的整车动力学模型与非线性状态估计算法的联合仿真平台,验证了两种滤波算法在复杂行驶工况下的估计精度、收敛性与鲁棒性,尤其针对传统传感器难以直接获取的状态变量提供了有效的解决方案。文中深入分析了非线性滤波理论在车辆状态估计中的适用性与优势,展示了其在提升车辆稳定性控制、先进驾驶辅助系统(ADAS)及自动驾驶系统感知能力方面的关键作用。; 适合人群:具备车辆动力学、现代控制理论及非线性滤波算法基础,熟练掌握MATLAB/Simulink仿真工具,从事智能网联汽车、自动驾驶、车辆状态估计与控制等领域的研究生、科研人员及工程技术开发者。; 使用场景及目标:① 掌握UKF与SRCKF算法的核心原理及其在车辆非线性系统建模中的实现方法;② 构建高精度车辆状态观测器,服务于车辆动力学控制、轨迹跟踪与安全性评估;③ 复现高水平学术论文中的仿真案例,提升科研仿真能力与算法验证水平。; 阅读建议:建议结合车辆动力学理论与卡尔曼滤波基础知识,逐步搭建并调试Simulink仿真模型,重点关注系统噪声与观测噪声的设定、协方差矩阵的初始化、滤波器的收敛行为及参数敏感性分析,后续可拓展至多源传感器融合(如IMU、GPS、轮速)的联合估计框架研究。

21,498

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧