Qtプログラミング関連Bug(記録)
環境:
Qt5.10.1;Qt quickプログラム;qmlとC++のインタラクション
質問:
1.error: ‘QMutex’ does not name a type:QMutex mutex;
理由:対応するクラスが含まれていません
ソリューション:追加:#include
2.TypeError: Property 'setMutex' of object xxxProcessor(0x117dae0) is not a function
元のコード:
ソリューション:コードを次のコードに変更
3.QQmlApplicationEngine failed to load component .Incorrectly specified signal assignment
元コード:MakeはC++で書かれたクラスです.Makeクラスはqmlタイプとして登録されています.以下のコードはxxxです.qmlファイルのバグを含むコードセグメント
ソリューション:コードを次のコードに変更します.
4.-1: error: collect2: error: ld returned 1 exit status
対応するコンパイル出力:
moc_xxx.o:関数‘XXXX::qt_static_Metacall(QObject*,QMetaObject::Call,int,void*)’中:..../moc_xxx.cpp:84:Make:doMake(QString,QString)’の未定義参照collect 2:error:ld returned 1 exit status
Makeはクラス名です.マイクがいるファイルcppファイル.
原因:文法エラーに類似する.
元のコード:
ソリューション:コードを次のコードに変更します.
5.error: invalid operands of types ‘const char [22]’ and ‘const char*’ to binary ‘operator+’
元のコード:
ソリューション:コードを次のコードに変更します.
Qt5.10.1;Qt quickプログラム;qmlとC++のインタラクション
質問:
1.error: ‘QMutex’ does not name a type:QMutex mutex;
理由:対応するクラスが含まれていません
ソリューション:追加:#include
2.TypeError: Property 'setMutex' of object xxxProcessor(0x117dae0) is not a function
元のコード:
Connections{
target: xxxProcessor
onOutputSentenceChanged:{
xxxProcessor.setMutex(0);
}
}
ソリューション:コードを次のコードに変更
Connections{
target: xxxProcessor
onOutputSentenceChanged:{
xxxProcessor.mutex=0;
}
}
3.QQmlApplicationEngine failed to load component .Incorrectly specified signal assignment
元コード:MakeはC++で書かれたクラスです.Makeクラスはqmlタイプとして登録されています.以下のコードはxxxです.qmlファイルのバグを含むコードセグメント
Make{
onOutputSentenceChanged{
}
}
ソリューション:コードを次のコードに変更します.
Make{
onOutputSentenceChanged:{
}
}
4.-1: error: collect2: error: ld returned 1 exit status
対応するコンパイル出力:
moc_xxx.o:関数‘XXXX::qt_static_Metacall(QObject*,QMetaObject::Call,int,void*)’中:..../moc_xxx.cpp:84:Make:doMake(QString,QString)’の未定義参照collect 2:error:ld returned 1 exit status
Makeはクラス名です.マイクがいるファイルcppファイル.
原因:文法エラーに類似する.
元のコード:
//Make.cpp
int doMake (QString source, QString result){
}
ソリューション:コードを次のコードに変更します.
//Make.cpp
int Make::doMake (QString source, QString result){
}
5.error: invalid operands of types ‘const char [22]’ and ‘const char*’ to binary ‘operator+’
元のコード:
std::string varStr1= "Error: "+e.what();
ソリューション:コードを次のコードに変更します.
std::string varStr1= "Error : ";
varStr1.append(e.what());