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

  2. #2
    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].

  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)

    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

    }

    }

    }

  4. #4
    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].

  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)

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

  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)

    set a break point in the slot which is called and look at trace log.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    can you also prepare minimal compilable project which we can build by ourself?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

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

  9. #9
    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)

    Quote Originally Posted by qtlinuxnewbie View Post
    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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  10. #10
    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)

    ::connect will work - ignore Visual studio and Intellisense. Test your app instead.

  11. #11
    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.