Qt学习 (三) : 一个简陋的调查问卷

本文介绍了一个使用Qt实现的简单TCP调查问卷系统,涵盖了客户端与服务器端的创建,通过TCP协议进行数据传输。在理解TCP协议的基础上,讨论了Qt中信号和槽的灵活性,以及槽函数的特点,加深了对Qt编程的理解。
摘要由CSDN通过智能技术生成

 

学习一点TCP网络协议的知识,利用Qt做一次调查问卷,客户端与服务器端如下:

服务器:    

客户端:    

 

客户端:

首先在创建的tcpclient工程下的tcpclient.pro中加入

QT += network

然后编写tcpclient.h

#ifndef TCPCLIENT_H
#define TCPCLIENT_H

#include <QDialog>
#include <QListWidget>
#include <QCheckBox>
#include <QPushButton>
#include <QLabel>
#include <QGridLayout>
#include <QHostAddress>
#include <QTcpSocket>
#include <QButtonGroup>
#include <QLineEdit>

class TcpClient : public QDialog
{
    Q_OBJECT

public:
    TcpClient(QWidget *parent = 0,Qt::WindowFlags f=0);
    ~TcpClient();
private:

    QString username1;

    QPushButton *saveBtn;
    QPushButton *submitBtn;


    QLabel *title;

    QLineEdit *lineedit1;
    QLabel *username;
    QPushButton *yesbutton;


    QLabel *question1;
    QLabel *question2;
    QLabel *question3;
    QLabel *question31;
    QLabel *question32;
    QLabel *question33;
    QLabel *question34;

    QButtonGroup *answer1;
    QButtonGroup *answer2;
    QButtonGroup *answer3A;
    QButtonGroup *answer3B;
    QButtonGroup *answer3C;
    QButtonGroup *answer3D;

    QCheckBox *answer11;
    QCheckBox *answer12;
    QCheckBox *answer13;

    QCheckBox *answer21;
    QCheckBox *answer22;

    QCheckBox *answer311;
    QCheckBox *answer312;

    QCheckBox *answer321;
    QCheckBox *answer322;

    QCheckBox *answer331;
    QCheckBox *answer332;

    QCheckBox *answer341;
    QCheckBox *answer342;

    QGridLayout *mainLayout;

    bool savestatus;
    bool submitstatus;

    int port;

    QHostAddress *serverIP;

    QTcpSocket *tcpSocket;

public slots:
    QString slotSave();
    void slotConnected();

    void getname();

    void slotSaveBox();
    void dataReceived();
    void slotSubmit();
    QString slotAnswer1();
    QString slotAnswer2();
};

#endif // TCPCLIENT_H

 

 

tcpclient.cpp

#include "tcpclient.h"
#include <QMessageBox>
#include <QHostInfo>

TcpClient::TcpClient(QWidget *parent,Qt::WindowFlags f)
    : QDialog(parent,f)
{
    setWindowTitle(tr("问卷调查"));

    title 
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值