Results 1 to 2 of 2

Thread: no match for 'operator<<' (operand types are 'QDebug' and 'const QSerialPortInfo')

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Qt products
    Platforms
    Unix/X11

    Default no match for 'operator<<' (operand types are 'QDebug' and 'const QSerialPortInfo')

    All of the following is on a Raspberry Pi 3 with Qt 5.3.2 (GCC 4.9.2, 32 bit).

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QtSerialPort/qserialportinfo.h>
    6. #include <QtSerialPort/qserialport.h>
    7. #include <QObject>
    8. #include <QtCore/QCoreApplication>
    9. #include <QDebug>
    10. #include <QList>
    11.  
    12.  
    13.  
    14. namespace Ui {
    15. class MainWindow;
    16. }
    17.  
    18. class MainWindow : public QMainWindow
    19. {
    20. Q_OBJECT
    21.  
    22. public:
    23. explicit MainWindow(QWidget *parent = 0);
    24.  
    25.  
    26. bool zaber_is_available;
    27. ~MainWindow();
    28.  
    29. private slots:
    30.  
    31.  
    32.  
    33. void on_Calibration_25mm_stage_move_button_clicked(int position);
    34.  
    35. void on_Calibration_25mm_stage_home_button_clicked();
    36.  
    37. void on_Calibration_25mm_stage_out_button_clicked();
    38.  
    39. void on_Calibration_300mm_stage_move_button_clicked(int position);
    40.  
    41. void on_Calibration_300mm_stage_home_button_clicked();
    42.  
    43. void on_Shot_tab_25mm_stage_move_button_clicked(int position);
    44.  
    45. void on_Shot_tab_25mm_stage_home_button_clicked();
    46.  
    47. void on_Shot_tab_25mm_stage_out_button_clicked();
    48.  
    49. void CommZaber(QString);
    50.  
    51. void on_Calibration_25mm_slider_sliderMoved(int position);
    52.  
    53. void on_Calibration_300mm_slider_sliderMoved(int position);
    54.  
    55. void on_Shot_tab_25mm_slider_sliderMoved(int position);
    56.  
    57. void on_Shot_tab_25mm_spinbox_valueChanged(int arg1);
    58.  
    59. void on_Calibration_300mm_spinbox_valueChanged(int arg1);
    60.  
    61. void on_Calibration_25mm_spinbox_valueChanged(int arg1);
    62.  
    63.  
    64. private:
    65. Ui::MainWindow *ui;
    66. QSerialPortInfo *serialPortInfo;
    67. QSerialPort *zaber;
    68.  
    69.  
    70. static const quint16 zaber_vendor_id = 0403;
    71. static const quint16 zaber_product_id = 6001;
    72.  
    73. };
    74.  
    75. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include <QPushButton>
    4. #include <QSpinBox>
    5. #include <QSlider>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10. MainWindow w;
    11. w.setWindowTitle("Compact 6 Radiometer Control Unit");
    12. w.show();
    13.  
    14.  
    15.  
    16.  
    17.  
    18.  
    19. return a.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QtSerialPort/qserialport.h>
    4. #include <QtSerialPort/qserialportinfo.h>
    5. #include <QObject>
    6. #include <QList>
    7. #include <QDebug>
    8. #include <QString>
    9. #include <QWidget>
    10. #include "qmath.h"
    11. #include <QIODevice>
    12.  
    13. QT_USE_NAMESPACE
    14.  
    15. char Reply_Bytes[6] ={0};
    16. qint64 maxSize = 6;
    17. int value[4];
    18. int value2[4];
    19. char position_command[6] = {0};
    20. double new_value;
    21. float conversion;
    22. float distance;
    23. const double global_x = pow(256,3);
    24. const double global_y = pow(256,2);
    25. const double global_z = pow(256,4);
    26. float input_position;
    27. int Cmd_Byte_6 = 0;
    28. int Cmd_Byte_5 = 0;
    29. int Cmd_Byte_4 = 0;
    30. int Cmd_Byte_3 = 0;
    31.  
    32. MainWindow::MainWindow(QWidget *parent) :
    33. QMainWindow(parent),
    34. ui(new Ui::MainWindow)
    35. {
    36. ui->setupUi(this);
    37.  
    38. zaber_is_available = false;
    39.  
    40. qDebug() <<"Number of ports: "<<QSerialPortInfo::availablePorts();
    41.  
    42. foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts())
    43. {
    44. qDebug()<< "Name: " << serialPortInfo.portName();
    45. qDebug()<< "Description: "<< serialPortInfo.description();
    46. qDebug()<< "Manufacturer: " << serialPortInfo.manufacturer();
    47. if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier())
    48. {
    49. qDebug() << "Has VendorID and ProductID:" << serialPortInfo.hasVendorIdentifier() <<
    50. "and" << serialPortInfo.hasVendorIdentifier();
    51. if(serialPortInfo.vendorIdentifier() == zaber_vendor_id)
    52. {
    53. qDebug() << "Vendor: " << serialPortInfo.vendorIdentifier();
    54. if(serialPortInfo.productIdentifier() == zaber_product_id)
    55. {
    56. qDebug() << "Product: " << serialPortInfo.productIdentifier();
    57. zaber = new QSerialPort;
    58. zaber_is_available = true;
    59. }
    60. }
    61. }
    62. }
    63.  
    64. //code removed as QDebug does not show in it and it is too long.
    65.  
    66. void MainWindow::CommZaber(QString command)
    67. {
    68. if(zaber->isWritable()){
    69. zaber->write(command.toStdString().c_str());
    70. }
    71. else{
    72. qDebug() << "Couldn't Write to Serial";
    73. }
    74.  
    75. }
    To copy to clipboard, switch view to plain text mode 

    The error I get is as stated in the post title. The pointer for the error leads me to the library, as if the error was in the library.

    I have tried adding the following to my header file to fix the issue but it did not work.
    Qt Code:
    1. class DebugClass : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit DebugClass(QObject *parent = 0);
    6. friend QDebug operator<< (QDebug dbg, const DebugClass &info){
    7. dbg.nospace() << "This is x: " <<info.x;
    8. return dbg.maybeSpace();
    9. }
    10.  
    11. private:
    12. int x;
    13. };
    To copy to clipboard, switch view to plain text mode 

    I have gotten this far by the good graces of Google. Any help would be greatly appreciated.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: no match for 'operator<<' (operand types are 'QDebug' and 'const QSerialPortInfo'

    How will defining operator<< for a totally unrelated class help solve the problem? The compiler is complaining because QSerialPortInfo::availablePorts() returns QList<QSerialPortInfo> and when you try to output this list through qDebug(), it can't find a match for "QDebug operator<<( QDebug, const QSerialPortInfo & )".

    When QDebug tries to serialize QList<T> (where in your case, T == QSerialPortInfo), it will take each member of the list and apply operator<<( QDebug, const T & ) to that member. This operator doesn't exist in the Qt library, so you'll have to write it. You have basically done that inside your foreach() loop.

    On the other hand, if all you are asking for in the first qDebug() statement in line 40 is the count of the available ports, then add ".size()" to the end of "QSerialPortInfo::availablePorts()".
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 7
    Last Post: 5th January 2016, 15:44
  2. Replies: 3
    Last Post: 29th January 2014, 15:23
  3. no match fo 'operator[]='
    By jeff28 in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2012, 10:53
  4. no match for 'operator=' in...
    By toss in forum Newbie
    Replies: 2
    Last Post: 14th April 2010, 01:08
  5. No match for operator>>
    By Salazaar in forum Newbie
    Replies: 18
    Last Post: 12th June 2007, 18:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.