Qt液晶显示器不工作
Posted
技术标签:
【中文标题】Qt液晶显示器不工作【英文标题】:Qt LCD display not working 【发布时间】:2014-06-23 06:41:14 【问题描述】:一旦连接,我正在尝试将 http get 连接流的输出输出到液晶屏幕(未来的 http 股票行情)。我的代码错误“C:\Qt5\Tools\QtCreator\bin\httpGET\mainwindow.cpp:16: error: no matching function for call to 'QLCDNumber::display() ui->lcdNumber->display()” I我不确定如何正确更新 display()
//主窗口.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(10);
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()));
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();
//主窗口.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();
【问题讨论】:
【参考方案1】:moving display() 修复了 lcd 输出问题。
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);
【讨论】:
以上是关于Qt液晶显示器不工作的主要内容,如果未能解决你的问题,请参考以下文章