基于QT写得一个小demo,大家参考下可以拿去套路一下女朋友哦
?主函数mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox> //按钮
#include<QMediaPlayer> //播放器
#include<QDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMediaPlayer* player=new QMediaPlayer;
//播放音乐
connect(player,SIGNAL(positionChanged(qint64)),
this,SLOT(positionChanged(qint64))
);
// player->setMedia(QUrl::fromLocalFile("D:/Qt/Documents/like/小乐哥 - 虞美人.mp3"));
// player->setMedia(QUrl::fromLocalFile("小乐哥 - 虞美人.mp3"));
player->setMedia(QUrl::fromLocalFile(":/resource/小乐哥 - 虞美人.mp3"));
player->play();
if(test==2){
player->stop();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
//接受
void MainWindow::on_pushButton_clicked()
{
test=2;
MainWindow();
QMediaPlayer* player=new QMediaPlayer;
//播放音乐
// connect(player,SIGNAL(positionChanged(qint64)),
// this,SLOT(positionChanged(qint64))
// );
// player->setMedia(QUrl::fromLocalFile("C:\\Users\\32041\\Desktop\\西黄\\小乐哥 - 虞美人.mp3"));
// player->play();
this->dia.show();
this->close();
}
//拒绝
void MainWindow::on_pushButton_2_clicked()
{
this->dia1.show();
ui->pushButton_2->move(button2_x=330,button2_y=150);
if(this->x_num==0){
this->dia1.close();
this->dia2.show();
ui->pushButton_2->move(button2_x=520,button2_y=280);
x_num=x_num+1;
}
else if(this->x_num==1){
this->dia1.close();
this->dia2.close();
this->dia3.show();
ui->pushButton_2->move(button2_x=490,button2_y=10);
x_num++;
}
else if(this->x_num==2){
this->dia1.close();
this->dia2.close();
this->dia3.close();
this->dia4.show();
ui->pushButton_2->move(button2_x=540,button2_y=280);
x_num++;
}
else if(this->x_num==3){
this->dia1.close();
this->dia2.close();
this->dia3.close();
ui->pushButton_2->move(button2_x=350,button2_y=270);
msgBox2->setText("好吧,看来我得在努力下才能追到小姐");
msgBox2->show();
}
}
?最终效果:
视频效果:?
|