我在不使用的QAudioRecorder
情况下使用时遇到了麻烦QMainWindow
。它将创建一个 0 字节的文件,在此处运行此脚本后,大多数普通媒体播放器都无法播放该文件:
int main(int argc, char *argv[]){
QAudioRecorder q;
q.setAudioInput(q.audioInputs()[0]);
q.setOutputLocation(QUrl::fromLocalFile("simon.amr"));
q.record();
Sleep(10000);
}
而这有效:
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
};
QAudioRecorder q;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
std::cout << "DEFAULT: " << q.defaultAudioInput().toStdString() << std::endl;
std::cout << "List: " << q.audioInputs().join(',').toStdString() << std::endl;
std::cout << "STATUS 0: " << q.status() << std::endl;
std::cout << "Location: " << QUrl::fromLocalFile("simon.amr").path().toStdString() << std::endl;
q.setAudioInput(q.audioInputs()[0]);
q.setOutputLocation(QUrl::fromLocalFile("simon.amr"));
q.record();
std::cout << "STATUS 1: " << q.status() << std::endl;
}
MainWindow::~MainWindow()
{
std::cout << "STATUS 2: " << q.status() << std::endl;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow recorder;
recorder.show();
return app.exec();
}
QAudioRecorder
没有我怎么使用QMainWindow
?难道我做错了什么?