c++ - gstreamermm和Qt编译错误

标签 c++ qt gstreamer qtgstreamer

我是 Qt 新手,我正在尝试使用 Qt 运行基本的 gstreamermm 示例。当我在 qt 的 main.cpp 中包含 gstreamermm.h 时,出现编译错误。我不明白这个错误说的是什么。我在本示例中使用 Qt Creator。

#include <QApplication>
#include <gstreamermm.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

我收到以下编译错误

g++ -c -pipe -g -pthread -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../Qt5.1.0/5.1.0/gcc_64/mkspecs/linux-g++ -I../PlayerBasic -I/usr/include/giomm-2.4 -I/usr/lib/x86_64-linux-gnu/giomm-2.4/include -I/usr/include/gstreamer-0.10 -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/libxml2 -I/usr/include/gstreamermm-0.10 -I/usr/lib/gstreamermm-0.10/include -I/usr/include/libxml++-2.6 -I/usr/lib/libxml++-2.6/include -I../../../../Qt5.1.0/5.1.0/gcc_64/include -I../../../../Qt5.1.0/5.1.0/gcc_64/include/QtWidgets -I../../../../Qt5.1.0/5.1.0/gcc_64/include/QtGui -I../../../../Qt5.1.0/5.1.0/gcc_64/include/QtCore -I. -I. -I. -o main.o ../PlayerBasic/main.cpp
In file included from /usr/include/glibmm-2.4/glibmm.h:92:0,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/glibmm-2.4/glibmm/balancedtree.h:225:40: error: macro "Q_FOREACH" requires 2 arguments, but only 1 given
In file included from /usr/include/gstreamermm-0.10/gstreamermm/query.h:30:0,
                 from /usr/include/gstreamermm-0.10/gstreamermm/message.h:33,
                 from /usr/include/gstreamermm-0.10/gstreamermm/element.h:34,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:28,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/gstreamermm-0.10/gstreamermm/structure.h:358:39: error: macro "Q_FOREACH" requires 2 arguments, but only 1 given
In file included from /usr/include/gstreamermm-0.10/gstreamermm.h:67:0,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/gstreamermm-0.10/gstreamermm/bufferlist.h:189:39: error: macro "Q_FOREACH" requires 2 arguments, but only 1 given
In file included from /usr/include/gstreamermm-0.10/gstreamermm.h:98:0,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/gstreamermm-0.10/gstreamermm/taglist.h:597:39: error: macro "Q_FOREACH" requires 2 arguments, but only 1 given
In file included from /usr/include/sigc++-2.0/sigc++/signal.h:8:0,
                 from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/sigc++-2.0/sigc++/signal_base.h: In constructor 'sigc::internal::temp_slot_list::temp_slot_list(sigc::internal::temp_slot_list::slot_list&)':
/usr/include/sigc++-2.0/sigc++/signal_base.h:181:50: error: value-initialization of reference type 'sigc::internal::temp_slot_list::slot_list& {aka std::list<sigc::slot_base>&}'
In file included from /usr/include/sigc++-2.0/sigc++/sigc++.h:80:0,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/sigc++-2.0/sigc++/signal.h: At global scope:
/usr/include/sigc++-2.0/sigc++/signal.h:617:44: error: ISO C++ forbids declaration of 'result_type' with no type [-fpermissive]
/usr/include/sigc++-2.0/sigc++/signal.h:630:5: error: 'static int sigc::internal::signal_emit0<T_return, T_accumulator>::result_type(sigc::internal::signal_impl*)' conflicts with a previous declaration
/usr/include/sigc++-2.0/sigc++/signal.h:598:47: note: previous declaration 'typedef typename T_accumulator::result_type sigc::internal::signal_emit0<T_return, T_accumulator>::result_type'
/usr/include/sigc++-2.0/sigc++/signal.h: In static member function 'static int sigc::internal::signal_emit0<T_return, T_accumulator>::result_type(sigc::internal::signal_impl*)':
/usr/include/sigc++-2.0/sigc++/signal.h:628:48: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:628:54: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:629:48: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:629:54: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h: In static member function 'static sigc::internal::signal_emit0<T_return, T_accumulator>::result_type sigc::internal::signal_emit0<T_return, T_accumulator>::emit_reverse(sigc::internal::signal_impl*)':
/usr/include/sigc++-2.0/sigc++/signal.h:647:56: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:647:62: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:648:56: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:648:62: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h: At global scope:
/usr/include/sigc++-2.0/sigc++/signal.h:672:44: error: ISO C++ forbids declaration of 'result_type' with no type [-fpermissive]
In file included from /usr/include/sigc++-2.0/sigc++/sigc++.h:80:0,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/sigc++-2.0/sigc++/signal.h:701:5: error: 'static int sigc::internal::signal_emit0<T_return, sigc::nil>::result_type(sigc::internal::signal_impl*)' conflicts with a previous declaration
In file included from /usr/include/sigc++-2.0/sigc++/sigc++.h:80:0,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/sigc++-2.0/sigc++/signal.h:661:20: note: previous declaration 'typedef T_return sigc::internal::signal_emit0<T_return, sigc::nil>::result_type'
/usr/include/sigc++-2.0/sigc++/signal.h: In static member function 'static int sigc::internal::signal_emit0<T_return, sigc::nil>::result_type(sigc::internal::signal_impl*)':
/usr/include/sigc++-2.0/sigc++/signal.h:684:33: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:685:27: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:688:24: error: expected primary-expression before '.' token
In file included from /usr/include/sigc++-2.0/sigc++/sigc++.h:80:0,
                 from /usr/include/glibmm-2.4/glibmm/thread.h:58,
                 from /usr/include/glibmm-2.4/glibmm.h:87,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/sigc++-2.0/sigc++/signal.h:692:31: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h: In static member function 'static sigc::internal::signal_emit0<T_return, sigc::nil>::result_type sigc::internal::signal_emit0<T_return, sigc::nil>::emit_reverse(sigc::internal::signal_impl*)':
/usr/include/sigc++-2.0/sigc++/signal.h:728:39: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:729:43: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:729:49: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:732:40: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:732:46: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h:736:47: error: expected primary-expression before '(' token
/usr/include/sigc++-2.0/sigc++/signal.h:736:53: error: expected primary-expression before '.' token
/usr/include/sigc++-2.0/sigc++/signal.h: At global scope:
/usr/include/sigc++-2.0/sigc++/signal.h:766:38: error: expected ')' before '*' token
In file included from /usr/include/glibmm-2.4/glibmm/value_custom.h:32:0,
                 from /usr/include/glibmm-2.4/glibmm/value.h:196,
                 from /usr/include/glibmm-2.4/glibmm/propertyproxy_base.h:25,
                 from /usr/include/glibmm-2.4/glibmm/propertyproxy.h:25,
                 from /usr/include/glibmm-2.4/glibmm/objectbase.h:24,
                 from /usr/include/glibmm-2.4/glibmm/wrap.h:26,
                 from /usr/include/glibmm-2.4/glibmm/containerhandle_shared.h:25,
                 from /usr/include/glibmm-2.4/glibmm/arrayhandle.h:23,
                 from /usr/include/glibmm-2.4/glibmm.h:91,
                 from /usr/include/gstreamermm-0.10/gstreamermm/bin.h:7,
                 from /usr/include/gstreamermm-0.10/gstreamermm.h:65,
                 from ../PlayerBasic/main.cpp:3:
/usr/include/c++/4.7/typeinfo:41:37: error: expected '}' before end of line
/usr/include/c++/4.7/typeinfo:41:37: error: expected unqualified-id before end of line
/usr/include/c++/4.7/typeinfo:41:37: error: expected '}' before end of line
/usr/include/c++/4.7/typeinfo:41:37: error: expected '}' before end of line
/usr/include/c++/4.7/typeinfo:41:37: error: expected declaration before end of line
make: *** [main.o] Error 1

非常感谢有关上述内容的任何帮助。

最佳答案

出现该错误是因为 Qt 将 foreach 宏定义为 Q_FOREACH 的简写。这与一些 gstreamermm 类中的 foreach 方法的声明冲突。

有几种可能的方法可以避免该问题:

  1. CONFIG += no_keywords 行添加到您的 Qt 项目文件中。请注意,您将无法使用 Qt 特定的关键字,例如信号。如果您已经使用它们(例如,因为它们是由 QtCreator 自动生成的),您可以将它们替换为 Q_SIGNALSQ_SLOTS 宏。

  2. 通过将 gstreamermm.h 放在 Qt header 之前来更改 header 包含的顺序。

  3. #undef foreach 放在包含 Qt header 之后、包含 gstreamermm.h 之前。

2 和 3 是不太优雅的解决方案,因为在使用编写良好的库的编写良好的应用程序中, header 包含的顺序并不重要,并且不应引入任何 #define#undefines ,除非所使用的库的文档明确指定,否则会影响包含的声明。

关于c++ - gstreamermm和Qt编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18424425/

相关文章:

c++ - CodeLite 如何构建应用程序?

c++ - 如果抛出的值匹配多个 catch 子句会发生什么?

c++ - 从 QAbstractListModel 中删除项目后 QML 崩溃

ffmpeg - 如何将 y4m 文件转换为 yuv?

c++ - 在 Windows 上使用 cmake 编译 gstreamer 应用程序

c++ - 将类的成员函数传递给回调函数?

c++ - join() 抛出 thread_resource_error?

c++ - 为什么选择 BSTR 以及如何将其转换为 QString?

Qt QFileDialog - 仅具有静态功能的 native 对话框?

c - 在 C++ 中使用 g_idle_add() 时出错,在 C 中同样有效