Solved How to output QList to standard console ?
-
Have you tried something like this?
for(int loop1 = 0; loop1 < BT_string_list.size(); loop1++) { cout << BT_string_list.at(loop1); }
-
@AnneRanch said in How to output QList to standard console ?:
I cannot figure out how to retrieve / print the actual names of the devices to console.
What about QBluetoothHostInfo::name():
Returns the user visible name of the host info object.
-
That is the problem - I get this error
and I do not know how to implement the correct operator <<
because QBluetoothHostInfo in not a QString ./media/z/DOC_COPY_LABEL/Projects /QT_TEST/TEST_Splitter/application_Form_1/application/mainwindow_form.cpp:97: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const QBluetoothHostInfo')
cout << BT_string_list.at(loop1);
^ -
@AnneRanch
The object you have there is a wholeQBluetoothHostInfo
. The error message tells you the<<
operator hasn't been written to cope with that. You can't convert a wholeQBluetoothHostInfo
to aQString
. @Pablo-J-Rogina is suggesting you output aQBluetoothHostInfo::name()
, just the name of it. So presumablycout << BT_string_list.at(loop1).name();
-
@AnneRanch My bad, try BT_string_list.at(loop1).name();
-
Sorry, still no good.
Here is the code
cout << BT_string_list.at(loop1).name();
won't even compile
qDebug ("DEBUG message %d, says: %s", BT_string_list.size(),BT_string_list.at(loop1).name());
runs but "prints" garbage
And error
/media/z/DOC_COPY_LABEL/Projects /QT_TEST/TEST_Splitter/application_Form_1/application/mainwindow_form.cpp:134: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'QString')
cout << BT_string_list.at(loop1).name();
^Same issue
the BT_string_list.at(loop returns "item" ( per doc ) and I have no clue what is "item" .The .name() , assuming it is a one of the items should return QString .
Neither qDebug or "loop ..." see a QString - that is the issue.In simple terms - I need to convert whatever type ins "item" to QString to be able to send it to console. I am open to options, but woudl like to stick with C++ std::cout . This QString intead of C++ "String" is making things unnecessary complicated to code in Qt.
-
@AnneRanch said in How to output QList to standard console ?:
the BT_string_list.at(loop returns "item" ( per doc ) and I have no clue what is "item" .
Wow, it's something you defined yourself...
QList<QBluetoothHostInfo> BT_string_list;
so "item" will be an object of class ___________ (please fill in the blanks)
-
@AnneRanch
std::cout knows nothing of QString, by default at least, but it can print std::stringstherefore:
cout << BT_string_list.at(loop1).name().toStdString();
-
-
@AnneRanch said in How to output QList to standard console ?:
qDebug ("DEBUG message %d, says: %s", BT_string_list.size(),BT_string_list.at(loop1).name());
runs but "prints" garbage
That's because you have not looked up the syntax or examples of
qDebug()
. Always use the (excellent) documentation! Look at https://doc.qt.io/qt-5/qdebug.html. See how it always uses the<<
operator? SoqDebug() << "DEBUG message " << BT_string_list.size() << ", says: " << BT_string_list.at(loop1).name();
-
This post is deleted!