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 7577101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:05:57+00:00 2026-05-30T17:05:57+00:00

I am trying to program an App that fetches files from a server. I

  • 0

I am trying to program an App that fetches files from a server.

I have a ‘Window’ class(mainwindow.cpp, which is a widget class that would be the UI) and then I have a ‘Backend’ class(Backend.cpp).

The GUI has a push button and two radio buttons. If the radio button “remote” is seleted, then upon clicking the push button will lead to fetching files from server.

However, there is some problem in the ‘connect’ call in Backend.cpp which I can’t figure out. The error I get is: no matching function call to ‘QObject::connect(QNetworkReply*&), const char[13], Backend* const, const char[20])’

Here are the codes:

ANSWER: Avoid circular inclusions!!!!
Here are the updated codes:

mainwindow.h

#ifndef WINDOW_H
#define WINDOW_H

#include <QWidget>
#include <QRadioButton>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QHostAddress>
#include <QFile>
#include <QUrl>

#include "Backend.h"
class QGroupBox;

class Window : public QWidget
{
    Q_OBJECT

public:
    Window(QWidget *parent = 0);
    QTcpSocket *conn;
    QFile *file;

    QUrl url;
    Backend backend_inst;

private:

    QRadioButton *button_local;
    QRadioButton *button_remote;
    QGroupBox *createPushButtonGroup();


private slots:
    void onClick_button1();
    void onCheck_local();
    void onCheck_remote();
};

#endif

mainwindow.c

#include <QtGui>

#include "mainwindow.h"

Window::Window(QWidget *parent)
    : QWidget(parent)
{
    QGridLayout *grid = new QGridLayout;
    grid->addWidget(createPushButtonGroup(), 1, 1);
    setLayout(grid);

    setWindowTitle(tr("File-Fetch App"));
    resize(480, 420);
}

QGroupBox *Window::createPushButtonGroup()
{

    QGroupBox *groupBox = new QGroupBox();

    QPushButton *pushButton1 = new QPushButton(tr("Fetch Files!!"));

    button_local = new QRadioButton(tr("&Download Files from Local Storage"));
    button_remote = new QRadioButton(tr("&Download Files from a Web-Server"));
    button_local->setChecked(1);


    connect(pushButton1,SIGNAL(clicked()), this, SLOT(onClick_button1()));

    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addWidget(pushButton1);
    vbox->addSpacing(50);
    vbox->addWidget(button_local);
    vbox->addWidget(button_remote);
    vbox->addStretch(1);
    groupBox->setLayout(vbox);

    return groupBox;
}

void Window::onClick_button1()
{
    QTextStream out(stdout);
    out << "fetch button clicked\n";
    if (button_local->isChecked()){
        onCheck_local();
    }
    else if (button_remote->isChecked()){
         onCheck_remote();
    }

}
void Window::onCheck_local()
{

    QTextStream out(stdout);
    out << "local update button checked\n";

}
void Window::onCheck_remote()
{
    QTextStream out(stdout);
    out << "remote update button checked\n";
    QString pathname= "http://192.168.1.1:8000/example.txt";
    QUrl webaddr = pathname;
   backend_inst.FetchFile(webaddr);
}

Backend.h

#ifndef BACKEND_H
#define BACKEND_H

#include <QObject>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QUrl>
#include <QTextStream>

class Backend : public QObject
{
    Q_OBJECT

public:

    Backend(QObject* parent=0);
    void FetchFile(QUrl fpath);

public slots:
    void getBytesFromFile();

private:
    QNetworkReply *reply;
    QNetworkAccessManager qnam;

};

#endif // BACKEND_H

Backend.cpp

#include "Backend.h"


Backend::Backend(QObject* parent)
    : QObject(parent)
{
}

void Backend::FetchFile(QUrl fpath)
{
    reply = qnam.get(QNetworkRequest(fpath));
    QObject::connect(reply, SIGNAL(readyRead()),this, SLOT(getBytesFromFile()));

    //qnam = new QNetworkAccessManager;
    //QObject::connect(&qnam, SIGNAL(finished(QNetworkReply*)), this, SLOT(getBytesFromFile()));
}

void Backend::getBytesFromFile(){

    QByteArray downloadedData;
    QTextStream out(stdout);
    out << "we are loading data from URL\n";
    downloadedData =reply->readAll();
    out << downloadedData;
    delete reply;

}

main.cpp

#include <QApplication>

#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Window window;
    window.show();
    return app.exec();
}
  • 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-05-30T17:05:58+00:00Added an answer on May 30, 2026 at 5:05 pm

    To use signals and slots, your classes (both signaling and slotting) must derive from QObject, i.e.

    #include "mainwindow.h"
    
    #include <QObject>
    
    class Backend : public QObject
    {
        Q_OBJECT
    public:
        Backend(QObject* parent=0);
    
    [...]
    
    Backend::Backend(QObject* parent)
        : QObject(parent)
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 files in my program: App_interface.h, App_interface.cpp, main.cpp. Im trying to compile
I am trying run a program from a qmake .pro file which modifies the
I am trying to program a simple Android app that will stream an internet
I am trying to make an app that plays MP3 songs. My program flow
I'm trying to program an app to discover wifi devices which are connecting to
I am trying to communicate an Erlang program with a simple Qt window app
I have an app that I'm trying to run on an intranet. On my
I have a C# console app that I'm trying to create that processes all
I am trying to call MSTest.exe from a simple console app that is executed
Imagine we have a program trying to write to a particular file, but failing.

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.