differentiate connect(signals/slots) and connect(TCP/ip)
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;
Re: differentiate connect(signals/slots) and connect(TCP/ip)
Try ::connect(...) and QObject::connect()
Re: differentiate connect(signals/slots) and connect(TCP/ip)
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
Re: differentiate connect(signals/slots) and connect(TCP/ip)
are you sure you are include the correct headers for socket programming? ::connect() should work fine
Re: differentiate connect(signals/slots) and connect(TCP/ip)
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.
Re: differentiate connect(signals/slots) and connect(TCP/ip)
if you use Qt, why don't you use QtNetwork module instead of using std functions?
Re: differentiate connect(signals/slots) and connect(TCP/ip)
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 ?
Re: differentiate connect(signals/slots) and connect(TCP/ip)
Quote:
Originally Posted by
qtlinuxnewbie
i dont have any idea about the QtNetwork modules.
read this.
Quote:
Originally Posted by
qtlinuxnewbie
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.
Re: differentiate connect(signals/slots) and connect(TCP/ip)
Show your code, then we can tell why. Probably you aren't using ::connect().
Re: differentiate connect(signals/slots) and connect(TCP/ip)
This is main.cpp
Quote:
#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
Quote:
#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
}
}
}
Re: differentiate connect(signals/slots) and connect(TCP/ip)
did you try to write like this?
Code:
if((gnConnectFailed=::connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr))) == -1)
Re: differentiate connect(signals/slots) and connect(TCP/ip)
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 ).
Re: differentiate connect(signals/slots) and connect(TCP/ip)
set a break point in the slot which is called and look at trace log.
Re: differentiate connect(signals/slots) and connect(TCP/ip)
can you also prepare minimal compilable project which we can build by ourself?
Re: differentiate connect(signals/slots) and connect(TCP/ip)
thnk u for ur support ..
i think it takes hrs to do .. but i wil try
is there any way..?
Re: differentiate connect(signals/slots) and connect(TCP/ip)
Quote:
Originally Posted by
qtlinuxnewbie
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.
Re: differentiate connect(signals/slots) and connect(TCP/ip)
::connect will work - ignore Visual studio and Intellisense. Test your app instead.