2013-05-06 97 views
0

我想用「QextSerialPort」打開我的Huwawei USB加密狗。QWinEventNotifier:只能用於用QThread啓動的線程

我的端口詳情如下

Port Name: 
Product ID: 
Physical Name: \Device\000000ca 
Vendor Id: 
Friend Name: SB 

Port Name: 
Product ID:? 
Physical Name: \Device\USBPDO-10 
Vendor Id: ? 
Friend Name: TH 

Port Name: COM3 
Product ID: 
Physical Name: \Device\BthModem0 
Vendor Id: 
Friend Name: Standard Serial over Bluetooth link (COM3) 

Port Name: COM4 
Product ID: 
Physical Name: \Device\BthModem2 
Vendor Id: 
Friend Name: Standard Serial over Bluetooth link (COM4) 

Port Name: COM5 
Product ID: 
Physical Name: \Device\BthModem1 
Vendor Id: 
Friend Name: Standard Modem over Bluetooth link 

Port Name: COM6 
Product ID:? 
Physical Name: \Device\000000e2 
Vendor Id: ? 
Friend Name: HUAWEI Mobile Connect - 3G Application Interface (COM6) 

Port Name: COM7 
Product ID:? 
Physical Name: \Device\000000e0 
Vendor Id: ? 
Friend Name: HUAWEI Mobile Connect - 3G Modem 

Port Name: COM8 
Product ID:? 
Physical Name: \Device\000000e3 
Vendor Id: ? 
Friend Name: HUAWEI Mobile Connect - 3G PC UI Interface (COM8) 

我試圖打開我的USB加密狗,這樣我就可以發送短信。以下是我開

#include "MyClass.h" 
#include <qstring.h> 
#include <qdebug.h> 


int main() 
{ 
    QextSerialPort *port = new QextSerialPort("COM7"); 
    port->open(QIODevice::ReadWrite); 
    cout << port->isOpen(); 

    system("pause"); 
    return 0; 

} 

代碼,當我運行這段代碼,我得到的是

QWinEventNotifier: Can only be used with threads started with QThread 
1 

這顯示了端口ID打開,但對於該消息?這是否意味着我無法繼續使用其他代碼?在我編寫任何其他代碼之前,我想知道這一點。請幫忙!

+0

而且,我會打電話到正確的端口?我對QT和USB編程非常陌生' – 2013-05-06 08:40:32

+0

任何不使用QtSerialPort(官方Qt 5插件)的原因,順便說一句? – lpapp 2013-11-13 16:07:58

回答

3

最有可能的,你需要創建一個QApplication,沒有它一樣的事件和信號許多事情/插槽將無法正常工作:

int main() 
{ 
    QApplication app; 

    QextSerialPort *port = new QextSerialPort("COM7"); 
    port->open(QIODevice::ReadWrite); 
    cout << port->isOpen(); 

    system("pause"); 

    return app.exec(); 
} 
+0

公頃,我需要輸入更快:P – UmNyobe 2013-05-06 08:49:55

+0

感謝您的答覆。但我應該導入哪個頭文件?我找不到「qapplication.h」 – 2013-05-06 09:04:35

+0

如果你沒有創建GUI應用程序,請使用[QCoreApplication](http://qt-project.org/doc/qt-4.8/qcoreapplication.html)代替 – thuga 2013-05-06 09:20:29