int main(int argc, char *argv[]){ QApplication app(argc, argv); QWidget *window = new QWidget; window->resize(200, 120); QPushButton *button1 = new QPushButton("BEEP!", window); button1->setGeometry(10, 10, 180, 40); /*QProcess *beep = new QProcess(window); beep->startDetached("mpg123 beep-1.mp3");*/ Вот этот кусок кода //QObject::connect(button1, SIGNAL(clicked()), beep, SLOT()); window->show(); return app.exec();}
#include <QtGui/QApplication>#include <stdio.h>#include "mainwindow.h"#include <QSound>#include <QPushButton>#include <QHBoxLayout>#include <QWidget>#include <QProcess>#include <QApplication>class Process : public QProcess{ Q_OBJECTpublic slots: void startProcess() { QProcess::startDetached("mpg123 beep-1.mp3"); }};int main(int argc, char *argv[]){ QApplication app(argc, argv); QWidget *window = new QWidget; window->resize(200, 120); QPushButton *button1 = new QPushButton("BEEP!", window); button1->setGeometry(10, 10, 180, 40); QProcess *beep = new QProcess(window); QObject::connect(button1, SIGNAL(clicked()), beep, SLOT(startProcess())); //QProcess::startDetached("mpg123 beep-1.mp3"); window->show(); return app.exec();}
#ifndef PROCESS_H#define PROCESS_H#include <QObject>#include <QProcess>class Process : public QProcess{Q_OBJECTpublic: explicit Process(QObject *parent = 0);public slots: void startProcess() { QProcess::startDetached("mpg123 beep-1.mp3"); }};#endif // PROCESS_H
#include <QtGui/QApplication>#include "mainwindow.h"#include <QPushButton>#include <QWidget>#include <QProcess>#include <QApplication>#include "process.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); QWidget *window = new QWidget; window->resize(200, 120); QPushButton *button1 = new QPushButton("BEEP!", window); button1->setGeometry(10, 10, 180, 40); Process *beep = new Process(); QObject::connect(button1, SIGNAL(clicked()), beep, SLOT(startProcess())); window->show(); return app.exec();}