Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Output to LCD from QNetworkAccessManager fails
Forum Updated to NodeBB v4.3 + New Features

Output to LCD from QNetworkAccessManager fails

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wuzamarine
    wrote on last edited by
    #1

    I am trying to make the output of an http get connection stream to an lcd screen (a future http stock ticker), once connected. My code errors with "C:\Qt5\Tools\QtCreator\bin\httpGET\mainwindow.cpp:16: error: no matching function for call to 'QLCDNumber::display() ui->lcdNumber->display()"

    @
    //mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QNetworkAccessManager>
    #include <QUrl>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QImageReader>
    #include <QDebug>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    nam = new QNetworkAccessManager();
    ui->lcdNumber->display();

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::connect()
    {
    QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),
    this, SLOT(finishedSlot(QNetworkReply*)));

    //ui->lcdNumber->display(10);
    QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),
    this, SLOT(on_pushButton_clicked()));
    display(nam);
    

    }

    void MainWindow::requestPage(){
    QUrl url("http://www.google.com");
    QNetworkReply* reply = nam->get(QNetworkRequest(url));
    }

    void MainWindow::finishedSlot(QNetworkReply* reply){
    QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    if (reply->error() == QNetworkReply::NoError)
    {
    QImageReader imageReader(reply);
    QImage pic = imageReader.read();
    QByteArray bytes = reply->readAll(); // bytes
    QString string(bytes); // string
    }

    else
    {
    
    }
    

    }

    void MainWindow::on_pushButton_clicked()
    {
    connect();
    requestPage();
    }

    //mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QObject>
    #include <QNetworkAccessManager>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);

    ~MainWindow();
    

    private:
    Ui::MainWindow *ui;

    public slots:
    void connect();
    void requestPage();
    void finishedSlot(QNetworkReply* reply);
    void on_pushButton_clicked();
    private slots:

    private:
    QNetworkAccessManager* nam;

    };

    #endif // MAINWINDOW_H

    //main.cpp

    #include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MainWindow mConnect;
    mConnect.show();
    
    return a.exec(&#41;;
    

    }
    @

    [edit: added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      First thing I would change is your "connect" method. You should rather use something like setupConnections. If I've read your code correctly, you don't update your lcd anywhere except the constructor. Also in your connect method you are creating an endless loop that will also have as a side effect the re-creation of all connections once you clicked your push button

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wuzamarine
        wrote on last edited by
        #3

        @SGaist I detected the endless loop.
        I am new to Qt and really not sure how to correct the connection. My instinct says to do display(nam) and update it with the object it's self. But this blows obvious errors.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wuzamarine
          wrote on last edited by
          #4

          making this change appears to of possibly fixed the display issue. Now I am stuck trying to figure out how to stop it from looping.

          @
          void MainWindow::finishedSlot(QNetworkReply* reply){
          QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
          QVariant redirectionTargetUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
          if (reply->error() == QNetworkReply::NoError)
          {
          QImageReader imageReader(reply);
          QImage pic = imageReader.read();
          QByteArray bytes = reply->readAll(); // bytes
          QString string(bytes); // string
          ui->lcdNumber->display(string);
          }
          @

          [editt: added missing coding tags @ SGaist]

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            remove the call to connect from on_Button_clicked and do it in the constructor

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved