qt视频播放器代码(vs下的qt视频播放功能)

1、 QSound,QSoundEffect,QMediaPlayer使用1) QSound 这种方法会创建一个子线程在后台播放。适用于主线程调用,子线程调用会报错。例:QSound::play(“test.wav”);2) QSoundEffect 适用于提示音,未压缩的音频文件例:QSoundEffect *effect=new QSoundEffect;effect->setSource(QUrl::fromLocalFile(“test.wav”));effect->setLoopCount(1); //循环次数effect->setVolume(0.25f); //音量 0~1之间effect->play();3) QMediaPlayer 一般用于做音视频播放器,支持wav mp3 avi格式,支持在线和本地文件播放例:QMediaPlayer *player = new QMediaPlayer;player->setMedia(QUrl::fromLocalFile(“test.mp3”));player->setVolume(50); //0~100音量范围,默认是100player->play();备注:QAudioOutput也可以播放wav。(QAudioInput) 这是针对IODevice
qt视频播放器代码(vs下的qt视频播放功能)

2、 R 字符串:QString str = R”(C:\desktop)”; 转义字符,省去路径中“\”手动转义成“\”3、 中文乱码问题:u8 中文:例u8“测试”,也可以用如下:#ifdef WIN32#pragma execution_character_set(“utf-8”)#endif

4、 状态机:QStateMachine *pMachine = new QStateMachine();QPushButton *pState = new QPushButton;QState *off = new QState();off->assignProperty(pState, “text”, “Off”);off->setObjectName(“off”);

QState *on = new QState();on->setObjectName(“on”);on->assignProperty(pState, “text”, “On”);off->addTransition(pState, &QPushButton::clicked, on);on->addTransition(pState, &QPushButton::clicked, off);pMachine->addState(off);pMachine->addState(on);

pMachine->setInitialState(off);pMachine->start();

5、 QPropertyAnimation动画QPropertyAnimation m_pAnimation = new QPropertyAnimation(this, “index”);明变量跟循环的函数 index//geometry Opacity posm_pAnimation->setDuration(1000); //一秒循环一次m_pAnimation->setLoopCount(-1); // 无线循环m_pAnimation->setStartValue(0); /起始indexm_pAnimation->setEndValue(3); // 结束indexm_pAnimation->start();

6、 关闭窗口的快捷键QWidget *w = new QWidget();QShortcut *shortCut = new QShortcut(Qt::CTRL Qt::Key_Q, w);connect(shortCut, SIGNAL(activated()), w, SLOT(close()));w->show();

7、 遍历QMapQMap<int , QString> map;for(auto each : map.toStdMap()) {qDebug() << “key: ” << each.first;qDebug() << “value: ” << each.second;};

介绍一下c 17对结构化遍历for (auto [key, value] : map) {cout << key << ” ” << value << endl;}

10、 QWebEngineView删除Cache和CookieQWebEngineSettings* setting = page()->settings();engineProfile->clearHttpCache();//删除缓存QWebEngineCookieStore *cookie = engineProfile->cookieStore();cookie->deleteAllCookies(); //删除cookie

11、 QCompleter 自动补全,用于combox或者lineedit12、 模板实现线程安全单例templateclass Singleton{public:static T& getInstance() {static T value_; //静态局部变量return value_;}

private:Singleton();~Singleton();Singleton(const Singleton&); //拷贝构造函数Singleton& operator=(const Singleton&); // =运算符重载};

发表评论

登录后才能评论