PDA

View Full Version : differentiate connect(signals/slots) and connect(TCP/ip)



qtlinuxnewbie
16th February 2010, 07:00
HI,

In my Qt project, i have a thread to connect server. when i write the code with
connect(sockfd,...)
Qt is assuming it, as the connect , which is used to connect signals and slots:confused::confused:
so how should i differentiate that???


Thnx in advance;

squidge
16th February 2010, 07:55
Try ::connect(...) and QObject::connect()

qtlinuxnewbie
16th February 2010, 08:14
i dont want the slots connect.
i need the tcp connect but qt is taking this connect as the slots and giving the error...
i tried .. but no use

nish
16th February 2010, 10:18
are you sure you are include the correct headers for socket programming? ::connect() should work fine

qtlinuxnewbie
16th February 2010, 10:37
Yes,
i am already using in the Main.cpp..
so if it fails to connect in main.cpp .
i have to reconnect so, i am implementing in separate thread to connect again.
but i am getting the above problem which i mentioned.

spirit
16th February 2010, 11:22
if you use Qt, why don't you use QtNetwork module instead of using std functions?

qtlinuxnewbie
16th February 2010, 11:38
i dont have any idea about the QtNetwork modules.
moreover i have already used std fnctions in main.cpp . it worked well
but in separate thread it is using the slot connect.
why ?

spirit
16th February 2010, 11:44
i dont have any idea about the QtNetwork modules.

read this (http://doc.trolltech.com/4.6/network-programming.html).


moreover i have already used std fnctions in main.cpp . it worked well
but in separate thread it is using the slot connect.
why ?
show us compilable example which reproduces the problem.

franz
16th February 2010, 11:45
Show your code, then we can tell why. Probably you aren't using ::connect().

qtlinuxnewbie
16th February 2010, 12:32
This is main.cpp

#include <QtGui/QApplication>
#include "vms.h"
#include "ConnectServer.h"

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <QMessageBox>
#include <QFile>

#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdint.h>
#include <assert.h>

#include "defines.h"
#include "structs.h"
#include "tsadc.h"


int thresholdValuesem;
void *cThresholdValueAddrs;
key_t semkey;
int shmid;
key_t key;
int gnSampleFactor;

int sockfd;
struct sockaddr_in serv_addr;
struct hostent *host_name;
int SERV_TCP_PORT;
char SERV_HOST_ADDR[20];
char gcPassword[20];

int gnConnectFailed;

tsadc adc;

int main(int argc, char *argv[])
{

bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family =AF_INET;
serv_addr.sin_addr.s_addr =inet_addr(SERV_HOST_ADDR);
serv_addr.sin_port =htons(SERV_TCP_PORT);

/*open a TCP socket */

if((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0)
{
vmslog << "VmsERROR:can't open stream socket" << "\n";
vmslog.flush();
}

/*connect to the server*/

if((gnConnectFailed=connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr))) == -1)
{
vmslog << "VmsERROR:can't connect to server" << "\n";
vmslog.flush();

}


QApplication a(argc, argv);
vms w;
w.show();
return a.exec();
}



this is the thread.cpp



#include "ConnectServer.h"
#include <QThread>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <netdb.h>

#include <QMessageBox>

extern int sockfd;
extern struct sockaddr_in serv_addr;
extern int gnConnectFailed;
extern struct hostent *host_name;
extern int SERV_TCP_PORT;
extern char SERV_HOST_ADDR[20];

ConnectServerThread::ConnectServerThread()
{

}

void ConnectServerThread::connectServer()
{

while(gnConnectFailed==-1)
{
/*Reconnect to the server*/

if((gnConnectFailed=connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr))) == -1)
{
//Connection Failed

}

}

}

spirit
16th February 2010, 12:39
did you try to write like this?


if((gnConnectFailed=::connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr))) == -1)

qtlinuxnewbie
16th February 2010, 12:44
i tried in the above manner
successful in compilation. .
but it is still taking the slots connect.(i can say this, as it gives the IntelliSense ).

spirit
16th February 2010, 12:48
set a break point in the slot which is called and look at trace log.

spirit
16th February 2010, 12:49
can you also prepare minimal compilable project which we can build by ourself?

qtlinuxnewbie
16th February 2010, 12:52
thnk u for ur support ..
i think it takes hrs to do .. but i wil try
is there any way..?

franz
16th February 2010, 13:06
i tried in the above manner
successful in compilation. .
but it is still taking the slots connect.(i can say this, as it gives the IntelliSense ).

IntelliSense is the most retarded completion system ever. Don't trust it to show exactly what the compiler thinks.

squidge
16th February 2010, 13:17
::connect will work - ignore Visual studio and Intellisense. Test your app instead.