PRO文件里 直接用斜杠加入第二个程序如widget_client
#-------------------------------------------------
#
# Project created by QtCreator 2021-03-06T09:10:37
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = point_to_point
TEMPLATE = app
SOURCES += main.cpp\
widget_server.cpp \
widget_client.cpp
HEADERS += widget_server.h \
widget_client.h
FORMS += widget_server.ui \
widget_client.ui
然后主函数如下,直接将W改个名字,比如S,就行了
#include "widget_server.h"
#include "widget_client.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget_server w;
w.move(100,100);
w.show();
widget_client s;
s.move(900,100);
s.show();
return a.exec();
}
这样一运行,就同时运行server和 client两个程序了。