2013-08-25 80 views
2

我是新來的Qt,我試圖運行使用Qt基本gstreamermm例子。當我在qt的main.cpp中包含gstreamermm.h時,出現編譯錯誤。我無法理解那個錯誤說的是什麼。本例中我使用Qt創建器。gstreamermm和Qt編譯錯誤

#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 

任何幫助上述關於真的讚賞。

回答

5

出現此錯誤是因爲Qt將foreach宏定義爲Q_FOREACH的簡寫。這與在幾個gstreamermm類中聲明foreach方法相沖突。

有幾種可能的方式來避免這個問題:

  1. 添加CONFIG += no_keywords線到你的Qt項目文件。請注意,您將無法使用Qt特定的關鍵字,例如signalsslots。如果你已經使用它們(例如,因爲它們是自動生成的QtCreator),你可以用Q_SIGNALSQ_SLOTS宏替換它們。

  2. 更改標題列入通過把gstreamermm.h Qt的頭前的秩序。

  3. #undef foreach放在包含Qt標題之後但在包括gstreamermm.h之前。

2和3是更優雅的解決方案中,由於報頭夾雜物的順序應該在使用精心編寫文庫的良好的應用程序沒有關係和一個不應該引入任何#define S或#undef分級表,其會影響包含的聲明,除非使用庫的文檔明確指定。

+0

現在我收到以下編譯錯誤 從../untitled/main.cpp:1:0包含的文件中: ../untitled/mainwindow.h:18:9:error:expected':'before'插槽' ../untitled/mainwindow.h:18:9:錯誤:'插槽'未命名類型 make:*** [main.o]錯誤1 – sap

+1

您是對的 - 'no_keywords' can打破現有的代碼。爲避免這種情況,請將'slots'更改爲'Q_SLOTS'。我已經更新了包含此評論的答案。 –

+0

工作!謝謝。但我真的不明白是什麼問題? – sap