局域网远程关机程序

帮朋友写的一个远程关机的小程序,参考一些网上大神的代码,加上自己的代码。


控制端:main.c

#include "shutdown.h"
#include <QApplication>
#include <QSound>
#include <QPalette>
 
int main(int argc, char *argv[])
{
  
    QApplication a(argc, argv);
    QSound::play("music.wav");
    shutdown w;
    w.setFixedSize(280,260);
    w.setWindowTitle(QObject::tr("关机程序"));
 
    w.setWindowFlags(Qt::WindowCloseButtonHint);
    w.setWindowOpacity(1);
    w.setAutoFillBackground(true);
 
    QPalette palette;
    palette.setBrush(QPalette::WindowText, Qt::red);
    palette.setBrush(QPalette::ButtonText, Qt::red);
    palette.setBrush(QPalette::Button, Qt::red);
    w.setPalette(palette);
    w.show();
    return a.exec();
}
 shutdown.cpp 

#include "shutdown.h"
#include "ui_shutdown.h"
#include <QDebug>
#include <QTimer>
#include <QTime>
#include <QDateTime>
#include <QLCDNumber>
#include <QMessageBox>
#include <QPalette>
#include <windows.h>
#include <QInputDialog>
#include <QByteArray>
#include <QDebug>
int shutdownTime = 0;
int second = -1;
shutdown::shutdown(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::shutdown)
{
  
    ui->setupUi(this);
    setAutoFillBackground(true);
    QPalette p = QPalette();
    p.setColor(QPalette::WindowText , Qt::red);    //设置某一个控件颜色的方法
    ui->lcdNumber->setPalette(p);
 
    QTimer *timer = new QTimer(this);   //新建一个定时器
    connect(timer,SIGNAL(timeout()),this,SLOT(showTime())); //信号与槽,时间到便触发
    connect(timer,SIGNAL(timeout()),this,SLOT(showCountDownTime()));    //倒计时的信号与槽
    connect(ui->setShutDownbt,SIGNAL(clicked(bool)),this,SLOT(showCountDownTime())); //倒计时信号与槽
    connect(timer,SIGNAL(timeout()),this,SIGNAL(showCountDownTime));
    timer->start(1000); //一秒刷新一次
    showTime(); //显示时间
    showCountDownTime();
    showColon=true; //显示分号
    ui->shutDownTime->setText(tr("      尚未设置")) ; //初始化关机时间lebel
    sender = new QUdpSocket(this);
    receiver = new QUdpSocket(this);
    receiver->bind(QHostAddress::LocalHost, 6665);
    connect(receiver, SIGNAL(readyRead()),this, SLOT(readPendingDatagrams()));
 
}
 
shutdown::~shutdown()
{
  
    delete ui;
}
 
void shutdown::readPendingDatagrams()
 {
  
    qDebug()<<"111122";
     while (receiver->hasPendingDatagrams())
     {
  
         QByteArray datagram;
         datagram.resize(receiver->pendingDatagramSize());
         receiver->readDatagram(datagram.data(), datagram.size());
          qDebug()<<datagram.data();
         //数据接收在datagram里
/* readDatagram 函数原型
qint64 readDatagram(char *data,qint64 maxSize,QHostAddress *address=0,quint16 *port=0)
*/
     }
 }
void shutdown::showTime()//显示系统时间
{
  
    QTime time 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值