[Qt-interest] USB Device Notifications (PDEV_BRAODCAST_PORT)

David Ching dc at remove-this.dcsoft.com
Sun May 2 02:29:47 CEST 2010


"Wm. G. Urquhart" <wgu at wurquhart.co.uk> wrote in message 
news:4BDC448C.9070007 at wurquhart.co.uk...
> However, when I do this all I get is a single character 'C'. But the 
> native windows application displays 'COM5' as I would expect.
>
> I've checked the project settings for UNICODE but there is nothing in the 
> Preprocessor Definitions set for this so I'm a bit confused to say the 
> least.
>
> Can anyone shed some light on this please?
>
> QT Code that doesn't work:
>
> bool USBEraser::winEvent(MSG * msg, long * result)
> {
> if (msg->message == WM_DEVICECHANGE)
> {
> PDEV_BROADCAST_HDR pDevHdr = (PDEV_BROADCAST_HDR) msg->lParam ;
> char name[256] = {0} ;
> switch(msg->wParam)
> {
> case DBT_DEVICEARRIVAL:
> {
> if (pDevHdr->dbch_devicetype == DBT_DEVTYP_PORT)
> {
> PDEV_BROADCAST_PORT pPort = (PDEV_BROADCAST_PORT) pDevHdr ;
> strncpy_s(name, 255, pPort->dbcp_name, 255) ;
> ui.statusBar->showMessage(tr("Device Name : %1").arg(name), 0) ;
> }

QString::arg() is taking name as a Unicode string.  You need to convert name 
from an ASCII string to a Unicode string, something like

    ui.statusBar->showMessage(tr("Device Name : 
%1").arg(QString::fromAscii(name)), 0) ;

-- David
 




More information about the Qt-interest-old mailing list