Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Qt上运行AudioOutput示例代码? 我试图运行这里列出的例子:我是C++和QT的新手,所以我搞不懂它们的意思。这就是我试图实现它的方式: #include <QtWidgets> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <fstream> #include <string> #include <QObject> #include <QAudioOutput> int main() { QFile sourceFile; // class member. QAudioOutput* audio; // class member. { sourceFile.setFileName("C:\\Documents\\ParadigmE3-shortened.wav"); sourceFile.open(QIODevice::ReadOnly); QAudioFormat format; // Set up the format, eg. format.setSampleRate(8000); format.setChannelCount(1); format.setSampleSize(8); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } audio = new QAudioOutput(format, this); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); audio->start(&sourceFile); } } #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 int main(){ QFile sourceFile;//类成员。 QAudioOutput*audio;//类成员。 { sourceFile.setFileName(“C:\\Documents\\ParadigmE3 shorted.wav”); open(QIODevice::ReadOnly); QAudioFormat格式; //设置格式,例如。 格式:setSampleRate(8000); 格式。setChannelCount(1); 格式设置示例(8); 格式化.setCodec(“音频/pcm”); setByteOrder格式(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo信息(QAudioDeviceInfo::defaultOutputDevice()); 如果(!info.isFormatSupported(格式)){ qWarning()开始(&sourceFile); } }_C++_Qt_Audio - Fatal编程技术网

如何在Qt上运行AudioOutput示例代码? 我试图运行这里列出的例子:我是C++和QT的新手,所以我搞不懂它们的意思。这就是我试图实现它的方式: #include <QtWidgets> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <fstream> #include <string> #include <QObject> #include <QAudioOutput> int main() { QFile sourceFile; // class member. QAudioOutput* audio; // class member. { sourceFile.setFileName("C:\\Documents\\ParadigmE3-shortened.wav"); sourceFile.open(QIODevice::ReadOnly); QAudioFormat format; // Set up the format, eg. format.setSampleRate(8000); format.setChannelCount(1); format.setSampleSize(8); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } audio = new QAudioOutput(format, this); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); audio->start(&sourceFile); } } #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 int main(){ QFile sourceFile;//类成员。 QAudioOutput*audio;//类成员。 { sourceFile.setFileName(“C:\\Documents\\ParadigmE3 shorted.wav”); open(QIODevice::ReadOnly); QAudioFormat格式; //设置格式,例如。 格式:setSampleRate(8000); 格式。setChannelCount(1); 格式设置示例(8); 格式化.setCodec(“音频/pcm”); setByteOrder格式(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo信息(QAudioDeviceInfo::defaultOutputDevice()); 如果(!info.isFormatSupported(格式)){ qWarning()开始(&sourceFile); } }

如何在Qt上运行AudioOutput示例代码? 我试图运行这里列出的例子:我是C++和QT的新手,所以我搞不懂它们的意思。这就是我试图实现它的方式: #include <QtWidgets> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <fstream> #include <string> #include <QObject> #include <QAudioOutput> int main() { QFile sourceFile; // class member. QAudioOutput* audio; // class member. { sourceFile.setFileName("C:\\Documents\\ParadigmE3-shortened.wav"); sourceFile.open(QIODevice::ReadOnly); QAudioFormat format; // Set up the format, eg. format.setSampleRate(8000); format.setChannelCount(1); format.setSampleSize(8); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } audio = new QAudioOutput(format, this); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); audio->start(&sourceFile); } } #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 int main(){ QFile sourceFile;//类成员。 QAudioOutput*audio;//类成员。 { sourceFile.setFileName(“C:\\Documents\\ParadigmE3 shorted.wav”); open(QIODevice::ReadOnly); QAudioFormat格式; //设置格式,例如。 格式:setSampleRate(8000); 格式。setChannelCount(1); 格式设置示例(8); 格式化.setCodec(“音频/pcm”); setByteOrder格式(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo信息(QAudioDeviceInfo::defaultOutputDevice()); 如果(!info.isFormatSupported(格式)){ qWarning()开始(&sourceFile); } },c++,qt,audio,C++,Qt,Audio,它与描述中的代码相同,只是在一个int main()函数中 对于函数末尾附近的行,我收到两个“在非成员函数中无效使用'this'错误”和一个“return statement with no value”错误。我肯定我做得不对。我尝试用代码创建一个单独的函数,并从main()调用它,但这导致调用新函数时出错。这是因为原始类位于类方法中,This单词指的是相关的类 在这里,您复制了主函数中的代码,而此失去了它的意义 您可以使用智能指针代替QAudioOutput,也可以仅使用堆栈对象作为QAudi

它与描述中的代码相同,只是在一个
int main()
函数中


对于函数末尾附近的行,我收到两个“在非成员函数中无效使用'this'错误”和一个“return statement with no value”错误。我肯定我做得不对。我尝试用代码创建一个单独的函数,并从
main()调用它
,但这导致调用新函数时出错。

这是因为原始类位于类方法中,
This
单词指的是相关的类

在这里,您复制了主函数中的代码,而
失去了它的意义

您可以使用智能指针代替QAudioOutput,也可以仅使用堆栈对象作为QAudioOutput,这意味着将
替换为
0
。但是,在connect中也会遇到同样的问题

如果周围有QCoreApplication,则可以使用QCoreApplication将此
替换为父级。但是,插槽名称仍然存在问题,因为它似乎也没有在任何地方定义

这是一个有点离题的话题,但是在这里包含整个QTWidget是没有意义的。这将降低编译的速度,即使在这种情况下这并不重要

QFile和QDebug也不包括在内。许多std包含也是不必要的。在一个名为main的函数中有一个“return;”语句,您需要返回一个整数。这也不会编译

这是您在一个非常简单的案例中可以得到的代码。虽然这是示例的一个切碎版本,但它可能有助于您理解错误:

#include <QAudioOutput>
#include <QFile>
#include <QDebug>
#include <QCoreApplication>

class AudioOutputTest : public QObject
{
    Q_OBJECT
    public Q_SLOTS:
        void handleStateChanged(QAudio::State state) {
            qWarning() << "state = " << state;
            qApp->exit();
        }
};

#include "main.moc"

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

    QFile sourceFile;
    QAudioOutput* audio;

    sourceFile.setFileName("ParadigmE3-shortened.wav");
    sourceFile.open(QIODevice::ReadOnly);

    QAudioFormat format;
    // Set up the format, eg.
    format.setSampleRate(8000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qWarning() << "Raw audio format not supported by backend, cannot play audio.";
        return 1;
    }

    audio = new QAudioOutput(format, &a);
    AudioOutputTest audioOutputTest;
    QObject::connect(audio, SIGNAL(stateChanged(QAudio::State)), &audioOutputTest, SLOT(handleStateChanged(QAudio::State)));
    audio->start(&sourceFile);

    return a.exec();
}
#包括
#包括
#包括
#包括
类音频输出测试:公共QObject
{
Q_对象
公共Q_槽:
void handleStateChanged(QAudio::State){

qWarning()通常,文档中的代码片段来自QT提供的示例项目。请查看全部内容,因为仅仅粘贴这段代码是行不通的。@RetiredInja:QT=Quick Time…一年多后,这个问题是否仍然没有解决?谢谢提醒。我没有看它,因为没有任何进展d这让我很头疼。但是,根据我现在对Qt的了解,我可以断定我的额外错误可能是由于Qt配置,而不是由于代码本身的错误。但是,我不太愿意批准它。我不确定它是否能工作。原因是。@Jamil:包括moc。我更新了帖子。请再试一次。Strange、 不过它在这里工作。不要担心完整路径,只需复制/粘贴代码即可。:-)我现在明白了。moc的完整路径是什么?这不起作用。它没有找到moc。我发现Qt很累人,不是我想要的,所以我放弃了。@JVE999:显然,你必须安装Qt并在路径中获得moc。这超出了范围您的请求。这有点不公平,我为您编写了一个工作代码,然后您不必验证,也不必选择它…:/I验证了它。我安装了QT。我根本找不到moc。这非常重要。您在“moc的完整路径是什么”一文中留下了令人失望的内容。