Results 1 to 2 of 2

Thread: qt simple tcp communication with ui projects

  1. #1
    Join Date
    Nov 2013
    Posts
    15
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default qt simple tcp communication with ui projects

    I want to create a simple Tcp Communication project but I get some problems and I dont know how to solve that problem. When I try to find solution all people tell add this code (QT += network)on .pro file but in ui projects I dont have any pro file so I dont know the find the solution.

    //commu.h

    Qt Code:
    1. #ifndef COMMU_H
    2. #define COMMU_H
    3.  
    4. #include <QtWidgets/QMainWindow>
    5. #include "ui_commu.h"
    6. #include <QtNetwork/QTcpSocket>
    7. #include <QObject>
    8. #include <QString>
    9.  
    10. class commu : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. commu(QWidget *parent = 0);
    16. ~commu();
    17.  
    18. void start(QString address, quint16 port);
    19.  
    20. private:
    21. Ui::commuClass ui;
    22. QTcpSocket client;
    23. public slots:
    24. void startTransfer();
    25. };
    26.  
    27. #endif // COMMU_H
    To copy to clipboard, switch view to plain text mode 

    //commu.cpp

    Qt Code:
    1. #include "commu.h"
    2. #include <QtNetwork/QHostAddress>
    3.  
    4. commu::commu(QWidget *parent)
    5. : QMainWindow(parent)
    6. {
    7. ui.setupUi(this);
    8.  
    9. connect(&client, SIGNAL(connected()),this,SLOT(startTransfer()));
    10. }
    11.  
    12. commu::~commu()
    13. {
    14. client.close();
    15. }
    16.  
    17.  
    18. void commu::start(QString address, quint16 port)
    19. {
    20. QHostAddress addr(address);
    21. client.connectToHost(addr, port);
    22. }
    23.  
    24. void commu::startTransfer()
    25. {
    26. client.write("Hello, world", 13);
    27. }
    To copy to clipboard, switch view to plain text mode 

    //main.cpp

    Qt Code:
    1. #include "commu.h"
    2. #include <QtWidgets/QApplication>
    3. #include <QtCore>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. commu w;
    9. w.show();
    10. return a.exec();
    11.  
    12. commu client;
    13. client.start("127.0.0.1", 8888);
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 


    I get the errors:

    Qt Code:
    1. 1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QTcpSocket::~QTcpSocket(void)" (__imp_??1QTcpSocket@@UAE@XZ) referenced in function "public: virtual __thiscall commu::~commu(void)" (??1commu@@UAE@XZ)
    2. 1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall commu::commu(class QWidget *)" (??0commu@@QAE@PAVQWidget@@@Z)
    3. 1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ) referenced in function "public: void __thiscall commu::start(class QString,unsigned short)" (?start@commu@@QAEXVQString@@G@Z)
    4. 1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z) referenced in function "public: void __thiscall commu::start(class QString,unsigned short)" (?start@commu@@QAEXVQString@@G@Z)
    5. 1>c:\users\sel\documents\visual studio 2010\Projects\commu\Win32\Debug\\commu.exe : fatal error LNK1120: 4 unresolved externals
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qt simple tcp communication with ui projects

    Quote Originally Posted by citix View Post
    I want to create a simple Tcp Communication project but I get some problems and I dont know how to solve that problem. When I try to find solution all people tell add this code (QT += network)on .pro file but in ui projects I dont have any pro file so I dont know the find the solution.
    What does "ui project" mean?

    If you are using some other build system than qmake, then you need to add the linker directive for QtNetwork through that build system's means.

    Cheers,
    _

Similar Threads

  1. QML and serious projects
    By BigSmartFastAndrey in forum General Discussion
    Replies: 1
    Last Post: 27th March 2012, 11:06
  2. Replies: 2
    Last Post: 7th September 2010, 22:19
  3. new projects ???
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2009, 11:21

Tags for this Thread

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.