Hello Everyone ,
I'am new to OOP and QT and i'm trying to write a simple chat program (client , server) with winsockets.
I Have an error which i don't seem to understand :
this is my code so far :
#include "pmessenger.h"
#include "ui_pmessenger.h"
#include <QMessageBox>
#include <winsock2.h>
SOCKET s;
PMessenger::PMessenger(QWidget *parent) : QMainWindow(parent), ui(new Ui::PMessenger)
{
ui->setupUi(this);
WSADATA wsadata;
if(WSAStartup(MAKEWORD(2,2),&wsadata)!=0)
{
QMessageBox::critical(this,"Error","Winsock Startup Failed",0,0);
this->close();
}
s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET)
{
QMessageBox::critical(this,"Error","Socket Creation Faild",0,0);
WSACleanup();
this->close();
}
SOCKADDR_IN server;
server.sin_family = AF_INET;
server.sin_port = htons(7676);
server.sin_addr.s_addr = inet_addr("my ip is here :D");
if(::connect(s,(sockaddr*)&server,sizeof(server))!=0)
{
QMessageBox::critical(this,"Error","Can't Connect",0,0);
WSACleanup();
this->close();
}
CreateThread(NULL,0,ServerMsgThread,(LPVOID)s,0,0); // the problem is in this line :(
}
PMessenger::~PMessenger()
{
delete ui;
}
void PMessenger::on_pushButton_clicked()
{
QString msg = ui->plainTextEdit_2->toPlainText();
send(s,(const char *)msg.data(),4096,0);
}
void PMessenger::AddMessege(char msg[4096])
{
ui->plainTextEdit->appendPlainText(msg);
}
DWORD PMessenger::ServerMsgThread(LPVOID pParam)
{
SOCKET Cs = (SOCKET) pParam;
char data[4096];
while(1)
{
if(recv(Cs,data,1024,0)>0)
AddMessege(data);
}
return 0;
}
I Get the following error :
..\PMessenger\pmessenger.cpp:32: error: argument of type 'DWORD (PMessenger:: )(void*)' does not match 'DWORD (*)(void*)'
Any help would be greatly appreciated (i really don't want to move to wxWidgets because of that error)
Thanks