qt6windows7/examples/network/rsslisting/rsslisting.h

55 lines
1.1 KiB
C
Raw Normal View History

2023-10-30 06:33:08 +08:00
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef RSSLISTING_H
#define RSSLISTING_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QWidget>
#include <QXmlStreamReader>
QT_BEGIN_NAMESPACE
class QLineEdit;
2023-11-02 01:02:52 +08:00
class QPushButton;
2023-10-30 06:33:08 +08:00
class QTreeWidget;
class QTreeWidgetItem;
2023-11-02 01:02:52 +08:00
class QUrl;
2023-10-30 06:33:08 +08:00
QT_END_NAMESPACE
2023-11-02 01:02:52 +08:00
//! [0]
2023-10-30 06:33:08 +08:00
class RSSListing : public QWidget
{
Q_OBJECT
public:
2023-11-02 01:02:52 +08:00
explicit RSSListing(const QString &url = QString(), QWidget *widget = nullptr);
2023-10-30 06:33:08 +08:00
public slots:
void fetch();
void finished(QNetworkReply *reply);
2023-11-02 01:02:52 +08:00
void consumeData();
2023-10-30 06:33:08 +08:00
void error(QNetworkReply::NetworkError);
private:
void parseXml();
void get(const QUrl &url);
2023-11-02 01:02:52 +08:00
// Parser state:
2023-10-30 06:33:08 +08:00
QXmlStreamReader xml;
QString currentTag;
QString linkString;
QString titleString;
2023-11-02 01:02:52 +08:00
// Network state:
2023-10-30 06:33:08 +08:00
QNetworkAccessManager manager;
QNetworkReply *currentReply;
2023-11-02 01:02:52 +08:00
// UI elements:
2023-10-30 06:33:08 +08:00
QLineEdit *lineEdit;
QTreeWidget *treeWidget;
QPushButton *fetchButton;
};
2023-11-02 01:02:52 +08:00
//! [0]
2023-10-30 06:33:08 +08:00
#endif