Results 1 to 17 of 17

Thread: differentiate connect(signals/slots) and connect(TCP/ip)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    so how should i differentiate that???


    Thnx in advance;

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: differentiate connect(signals/slots) and connect(TCP/ip)

    Try ::connect(...) and QObject::connect()

  3. #3
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ?

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: differentiate connect(signals/slots) and connect(TCP/ip)

    Quote Originally Posted by qtlinuxnewbie View Post
    i dont have any idea about the QtNetwork modules.
    read this.
    Quote Originally Posted by qtlinuxnewbie View Post
    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: differentiate connect(signals/slots) and connect(TCP/ip)

    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

    }

    }

    }

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: differentiate connect(signals/slots) and connect(TCP/ip)

    did you try to write like this?
    Qt Code:
    1. if((gnConnectFailed=::connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr))) == -1)
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ).

  12. #12
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: differentiate connect(signals/slots) and connect(TCP/ip)

    Show your code, then we can tell why. Probably you aren't using ::connect().
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Replies: 18
    Last Post: 25th January 2010, 11:23
  2. how to connect events with signals in QGraphicsScene?
    By nataly in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2009, 15:20
  3. Connect to...without slots...
    By Peppy in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 13:47
  4. Replies: 12
    Last Post: 23rd June 2008, 08:05
  5. function 'connect' always look super class for slots.
    By Intaek Lim in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2007, 13:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.