在Qt中要動態載入DLL檔可以用QLibrary來載入
首先
#include < QLibrary >
定義Function
typedef void (*Function_Name)(int 參數1,int 參數2 , ...);
然後在程式中載入的方法是
QLibrary testlib("DLL_Name"); //此處DLL_Name不用加.dll
if(test_lib.load())//載入dll並判斷是否成功
{
qDebug()<<"load dll ok.";
//宣告Function(DLL_Function_Name為DLL檔裡定義的Function名稱)
Function_Name test_function = (Function_Name)test_lib.resolve("DLL_Function_Name");
//現在可以使用Function了
if(test_function)
{
int a = 0;
int b = 0;
test_function( a, b );
}
}else{
qDebug()<<"load dll fail.";
}
2011年2月23日 星期三
2011年2月9日 星期三
Qt 4.7 Tcp Socket Client 教學範例
首先在專案的.pro檔中要先加入
QT += network
接著在程式.h檔中加入
在程式.cpp裡
QT += network
接著在程式.h檔中加入
#include < QtNetwork/QTcpSocket >
//宣告一個QTcpSocket方便在整個程式中使用
QTcpSocket *m_socket;
在程式.cpp裡
//產生QTcpSocket物件
m_socket = new QTcpSocket(this);
//Connect事件觸發的Function
//在收到Server的訊息時會觸發readRead()
connect(m_socket,SIGNAL(readyRead()),this,SLOT(slotReadyRead()));
//連線成功的事件
connect(m_socket,SIGNAL(connected()),this,SLOT(slotConnected()));
//斷線的事件
connect(m_socket,SIGNAL(disconnected()),this,SLOT(slotDisConnected()));
//連線到Server
QString ip_address="127.0.0.1";
int port = 2266
m_socket->connectToHost(ip_address,port );
//傳送訊息
QTextStream stream(m_socket);
stream << "Server: Hi, I am client";
//接收訊息
m_socket->readAll();
參考網址
Qt Network Tutorial
http://www.qtforum.org/article/9/qt-network-tutorial.html
Blocking Fortune Client Example
http://2s22.ing.ula.ve/qt/network-blockingfortuneclient.html
How to write Socket program in Qt 4.7 for Mobiles?
http://discussion.forum.nokia.com/forum/showthread.php?217630-How-to-write-Socket-program-in-Qt-4.7-for-Mobiles
Qt Network Tutorial
http://www.qtforum.org/article/9/qt-network-tutorial.html
Blocking Fortune Client Example
http://2s22.ing.ula.ve/qt/network-blockingfortuneclient.html
How to write Socket program in Qt 4.7 for Mobiles?
http://discussion.forum.nokia.com/forum/showthread.php?217630-How-to-write-Socket-program-in-Qt-4.7-for-Mobiles
訂閱:
文章 (Atom)