Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:08+00:00 2026-06-12T02:28:08+00:00

I am working with Qt creator to make a GUI program that takes in

  • 0

I am working with Qt creator to make a GUI program that takes in different URLs and will download and display the html code.

The user can add different URLs to a listWidget. Then the user can select a specific URL and download the html which will be displayed beside the list of URLs.

The problem I am having is getting the text area to update after the reply is received.

main.cpp – Basically just shows the window.

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "htmlmanager.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

mainwindow.h – Pretty straight forward. Contains the object html that will be used to request the html from the inputted website.

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "htmlmanager.h"
#include <QString>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
    Q_OBJECT

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

private slots:
    void on_addButton_clicked();
    void on_actionExit_triggered();
    void on_removeButton_clicked();
    void on_downloadButton_clicked();
private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

mainwindow.cpp – This is the beginning of the problem. If you look down at the “downloadButton_clicked()” function, you see that it fetches the html by sending a request. However, the reply isn’t recieved before the next line so the text field is set to “”.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

}

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

void MainWindow::on_addButton_clicked()
{
    if(!ui->lineEdit->text().isEmpty())
    {
        ui->listWidget->addItem(ui->lineEdit->text());
    }
    else
    {
        qDebug() << "Input field is empty.";
    }
}

void MainWindow::on_actionExit_triggered()
{
    //doesn't do anything right now
}

void MainWindow::on_removeButton_clicked()
{
    if(ui->listWidget->currentItem()) //If an item is selected
    {
        delete ui->listWidget->currentItem();
    }
    else
    {
        qDebug() << "No selection";
    }
}

void MainWindow::on_downloadButton_clicked()
{
    if(ui->listWidget->currentItem()) //If an item is selected
    {
        html.fetch(ui->listWidget->currentItem()->text());
        ui->textBrowser->setText(html.str);
    }
    else
    {
        qDebug() << "No selection";
    }

}

htmlmaneger.h

#ifndef HTMLMANAGER_H
#define HTMLMANAGER_H

#include <QObject>
#include <QDebug>
#include <QtNetwork>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QString>


class HtmlManager : public QObject
{
    Q_OBJECT
    public:
        HtmlManager();
        void fetch(QString Url);
        QString str;

    public slots:
        void replyFinished(QNetworkReply* pReply);

    private:
        QNetworkAccessManager* m_manager;
};

#endif // HTMLMANAGER_H

htmlmanager.cpp – Once the reply is received, it stores the html in the QString “str”

#include "htmlmanager.h"

HtmlManager::HtmlManager()
{
    m_manager = new QNetworkAccessManager(this);
    connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}
void HtmlManager::fetch(QString Url)
{
    m_manager->get(QNetworkRequest(QUrl(Url)));
    qDebug() << "Sending network request.";
}
void HtmlManager::replyFinished(QNetworkReply* pReply)
{
    qDebug() << "Recieved network reply.";
    QByteArray data=pReply->readAll();
    str = data;
}

Is there an easy way to send the value of str to the MainWindow class once the reply is received, or is there a way for the onclick function to wait to update the text area until after a reply is received?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:28:10+00:00Added an answer on June 12, 2026 at 2:28 am

    You definitely don’t want to wait for a reply in your onClick() function. That will cause your program to be unresponsive until the network request comes it (which could very well take “forever”).

    One way to attack this would be to add a signal to your HtmlManager class. Something maybe called stringReceived. Then, in your mainwindow class you’d just need to add a line like this:

    connect(html, SIGNAL(stringReceived(QString)), ui->textBrowser, SLOT(setText(QString));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project I'm working on in Qt creator that requires a third-party
I am working with QT Creator. I have a form that contains a push
I am working on pdf creator in Asp.net with c#. In my code it
I'm trying to import some working Visual C++ code into Qt Creator and I'm
Working with an undisclosed API, I found a function that can set the number
Working on game where plates will be falling from top to bottom. Some plates
I'm trying to use Qt Creator, but it is not working. My hello world
When I first started working with Qt, it was extremely annoying that every class
I've been working on a project that requires draft/live versions of content and have
This is what my code looks like: case Creator: br.Read(); br.MoveToContent(); // gives the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.