PDA

View Full Version : QString::fromStdWString() doesn't work ...



jsmax
15th March 2006, 16:53
Hi guys, i have this peace of code:

//-------------------------------------------------------------------------------//
#include <QtGui>
#include <windows.h>
#include <lm.h>
.................................................. ...................
PSHARE_INFO_502 BufPtr,p;
NET_API_STATUS res;
DWORD er=0,tr=0,resume=0, i;
QString *str = new QString;
QTreeWidgetItem *rootItem = new QTreeWidgetItem(SharesTree);
rootItem->setText(0,"My Shares");
QTreeWidgetItem *item;

do
{
res = NetShareEnum (NULL, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
{
p=BufPtr;
for(i=1;i<=er;i++)
{
item = new QTreeWidgetItem(rootItem);
str->fromStdWString(p->shi502_netname);
item->setText(0,str);
p++;
}
NetApiBufferFree(BufPtr);
}
}
while (res==ERROR_MORE_DATA);

SharesTree->expandItem(rootItem);
.................................................. ............................
//----------------------------------------------------------------------------------------//

I'm using Qt4.1.1_opensource_mingw on Windows. It was configured like this:
configure -stl
and then
make

The program is building with success, but the fromStdWString function doesn't work ... :confused: What's wrong ??

Thanks a lot ...

Byngl
15th March 2006, 16:57
fromStdWString doesn't modify the string passed in, it returns a modified copy. Try assigning the return value to a temporary QString and passing that to setText().

jsmax
15th March 2006, 17:02
Thanks a lot ! It works ! I did it like that:

QString str;

item = new QTreeWidgetItem(rootItem);
str = QString::fromStdWString(p->shi502_netname);
item->setText(0,str);