I need to store/get pointer to raw data
here my test code
#include <QtCore>
#include <QtGui>
#include "qttest.h"
#include <string.h>
#include <stdio.h>
qttest
::qttest(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
ui.
treeWidget->setHeaderLabels
(QStringList() <<
"#" <<
"Name" <<
"Count" );
for(int i=0;i<50;i++){
item
->setText
(0,
QString::number(i
));
item->setText(1,tr("Item %1").arg(i) );
//item->setToolTip(1,"<b>hello's <br>QT</b>");
unsigned char *data = new unsigned char [1024];
strcpy((char*)data,"Hello world");
item->setData(0,Qt::UserRole,data);
item->setText(2,count );
ui.treeWidget->addTopLevelItem(item);
}
}
qttest::~qttest()
{
}
void qttest::on_listWidget_currentRowChanged(int)
{
}
{
//QString text = ui.treeWidget->currentItem()->text(1);
char *num =(char*) ui.treeWidget->currentItem()->data(0,Qt::UserRole).value< char* >();
ui.listWidget->addItem(num);
}
#include <QtCore>
#include <QtGui>
#include "qttest.h"
#include <string.h>
#include <stdio.h>
qttest::qttest(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
ui.treeWidget->setHeaderLabels(QStringList() << "#" << "Name" << "Count" );
QTreeWidgetItem *item =0;
for(int i=0;i<50;i++){
item = new QTreeWidgetItem(ui.treeWidget);
item->setText(0,QString::number(i));
item->setText(1,tr("Item %1").arg(i) );
//item->setToolTip(1,"<b>hello's <br>QT</b>");
unsigned char *data = new unsigned char [1024];
strcpy((char*)data,"Hello world");
item->setData(0,Qt::UserRole,data);
QString count = QString::number(rand()%100);
item->setText(2,count );
ui.treeWidget->addTopLevelItem(item);
}
}
qttest::~qttest()
{
}
void qttest::on_listWidget_currentRowChanged(int)
{
}
void qttest::on_treeWidget_doubleClicked(QModelIndex)
{
//QString text = ui.treeWidget->currentItem()->text(1);
char *num =(char*) ui.treeWidget->currentItem()->data(0,Qt::UserRole).value< char* >();
ui.listWidget->addItem(num);
}
To copy to clipboard, switch view to plain text mode
Code can't compile ,here error
Error 1 error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>' e:\qt\4.2.2\src\corelib\kernel\qmetatype.h 166
Error 1 error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>' e:\qt\4.2.2\src\corelib\kernel\qmetatype.h 166
To copy to clipboard, switch view to plain text mode
Thank you in advance.
Bookmarks