qt5程序1,功能:一个屏幕控制,一个显示视频

pro.文件

#-------------------------------------------------
#
# Project created by QtCreator 2018-12-26T15:51:22
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled2
TEMPLATE = app

QT += multimedia
QT += multimediawidgets
QT += axcontainer

SOURCES += main.cpp\
        mainwindow.cpp \
    form.cpp

HEADERS  += mainwindow.h \
    form.h

FORMS    += mainwindow.ui \
    form.ui

mainwindow.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include "form.h"
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QMediaPlaylist>
#include <QtMultimedia>
#include <QtMultimediaWidgets>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    Form ff;
  //  QWidget* widget=new QWidget;
    QMediaPlayer *player=new QMediaPlayer;
    QMediaPlaylist *playlist=new QMediaPlaylist;
    QVideoWidget *videoWidget=new QVideoWidget;
    QVBoxLayout*laa=new QVBoxLayout;

    QDesktopWidget *desk = QApplication::desktop();

    QTimer *update_time=new QTimer(this);  //定义定时器类

    qint64 bb;

private slots:
    void on_pushButton_clicked();
    void time1();
    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

private:
    Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H

mainwindow.cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "form.h"
#include "ui_form.h"
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QMediaPlaylist>
#include <QtMultimedia>
#include <QtMultimediaWidgets>
#include<QDebug>
#include<QVBoxLayout>
#include<QWidget>
#include<QDesktopWidget>
#include"time.h"



MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    int N = desk->screenCount();
  //显示第二屏幕
      if(N>0)
      {
       ff.setGeometry(desk->screenGeometry(1));
       ff.show();
       qDebug()<<N;
      }

      videoWidget->setAspectRatioMode(Qt::IgnoreAspectRatio);
      videoWidget->setFullScreen(true);
      laa->addWidget(videoWidget);
       ff.setLayout(laa);
     playlist->addMedia(QUrl::fromLocalFile("E:\\move\\01.mp4"));//两种添加路经的方式
     playlist->addMedia(QUrl::fromLocalFile("E:\\move\\02.mp4"));//两种添加路经的方式
     playlist->addMedia(QUrl::fromLocalFile("E:\\move\\03.mp4"));//两种添加路经的方式
     player->setVideoOutput(videoWidget);
     player->setPlaylist(playlist);
     videoWidget->show();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{




   playlist->setCurrentIndex(0);  //设置播放视频内容
   ff.showFullScreen();          //设置全屏显示
 //  ff.setGeometry(desk->screenGeometry(1));
   player->play();              //开始播放



   connect(update_time,SIGNAL(timeout()),this,SLOT(time1()));//  连接时间函数

   update_time->start(1000);  //定时1s

   qDebug()<<"aaaa";      //打印内容

}

void MainWindow::time1()
{
    bb=player->position();//获取视频进度
    qDebug()<<bb;
}


void MainWindow::on_pushButton_2_clicked()
{


    playlist->setCurrentIndex(1);
    ff.showFullScreen();
  //  ff.setGeometry(desk->screenGeometry(1));
    player->play();
    connect(update_time,SIGNAL(timeout()),this,SLOT(time1()));//  连接时间函数
    update_time->start(1000);  //定时1s
}

void MainWindow::on_pushButton_3_clicked()
{
    playlist->setCurrentIndex(2);
    ff.showFullScreen();
  //  ff.setGeometry(desk->screenGeometry(1));
    player->play();
    connect(update_time,SIGNAL(timeout()),this,SLOT(time1()));//  连接时间函数
    update_time->start(1000);  //定时1s
}

main.cpp文件

#include "mainwindow.h"
#include <QApplication>
#include<QDesktopWidget>
#include "form.h"
#include<QDebug>
#include<QTimer>



int main(int argc, char *argv[])
{
    QApplication a(argc, argv);


    MainWindow w;
    w.show();





    return a.exec();
}

另外还有加上一个form窗口文件
显示窗口图

在这里插入图片描述

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是一个简单的QT程序计数器,每1秒计数一次,每5秒停止计数: ```cpp #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtWidgets/QLabel> #include <QtCore/QTimer> class CounterWidget : public QWidget { public: CounterWidget(QWidget* parent = nullptr) : QWidget(parent) { countLabel = new QLabel("0", this); countLabel->setAlignment(Qt::AlignCenter); countLabel->setGeometry(0, 0, width(), height()); count = 0; countTimer = new QTimer(this); countTimer->setInterval(1000); connect(countTimer, &QTimer::timeout, this, &CounterWidget::onCountTimerTimeout); stopTimer = new QTimer(this); stopTimer->setInterval(5000); connect(stopTimer, &QTimer::timeout, this, &CounterWidget::onStopTimerTimeout); stopTimer->start(); } private: QLabel* countLabel; QTimer* countTimer; QTimer* stopTimer; int count; void onCountTimerTimeout() { count++; countLabel->setText(QString::number(count)); } void onStopTimerTimeout() { countTimer->stop(); stopTimer->stop(); } }; int main(int argc, char* argv[]) { QApplication app(argc, argv); CounterWidget counterWidget; counterWidget.show(); return app.exec(); } ``` 在这个程序中,我们创建了一个计数器窗口,其中包含一个用于显示计数的标签。我们使用两个定时器,一个用于每秒钟增加计数器,另一个用于在5秒后停止计数器。我们使用`QTimer`类来实现这两个定时器,使用`connect`函数来连接定时器的超时信号和我们自己定义的槽函数。在计数器超时槽函数中,我们增加计数器并更新标签。在停止计时器超时槽函数中,我们停止计数器定时器和停止定时器。最后,我们在`main`函数中创建一个应用程序对象,创建计数器窗口并显示它,然后启动应用程序事件循环。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值