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. [SOLVED] Older Version of Qt Tutorial Issue (v4.7 -> v5.1)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Older Version of Qt Tutorial Issue (v4.7 -> v5.1)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.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.
  • K Offline
    K Offline
    kingsta
    wrote on 11 Oct 2013, 22:11 last edited by
    #1

    Hi guys.

    I want to make a program which gets the datas from the Internet via Web Services. I found a tutorial. Its good. Here "the tutorial":http://doc.qt.digia.com/qq/qq23-web-service.html.

    All of things are good. This tutorial perfectly runs on Qt 4.7. I have a problem with Qt 5.1. This tutorial made on older version of Qt 5.1 (like as Qt 4.7). So various functions, various classes etc. changed on Qt 5.1, you know. For example there is no QHttp include file. I guess I have to use QNetworkAccessManager include file. How can i convert the codes from older version of Qt to Qt 5.1?

    QUrl include file doesn't support the setQueryDelimiters(), addQueryItem() etc. (on Qt 5.1). I add the QUrlQuery include file and declare the QUrlQuery variable for that functions but I still have a problem.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 14 Oct 2013, 02:15 last edited by
      #2

      Hi,

      You are heading in the right direction: QNetworkAccessManager is the replacement for QHttp. QUrlQuery has taken over the functions of setQueryDelimiters(), addQueryItem() etc.

      See http://qt-project.org/doc/qt-5.1/qtdoc/sourcebreaks.html for a full list of changes between Qt 4 and Qt 5.

      [quote]How can i convert the codes from older version of Qt to Qt 5.1?[/quote]Have a look at the documentation:

      • http://qt-project.org/doc/qt-5.1/qtnetwork/qnetworkaccessmanager.html
      • http://qt-project.org/doc/qt-5.1/qtcore/qurlquery.html

      [quote author="kingsta" date="1381529473"]I add the QUrlQuery include file and declare the QUrlQuery variable for that functions but I still have a problem.[/quote]You need to provide details of the problem, or else we won't know how to help you.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kingsta
        wrote on 14 Oct 2013, 09:08 last edited by
        #3

        I changed codes. Now, Program can run. But It doesn't work correctly.

        When I run the program, I got the
        @QObject::connect: Incompatible sender/receiver arguments
        QNetworkAccessManager::finished(QNetworkReply*) --> MainWindow::updateForm(bool)@
        error.

        When I press the updateButton, I got the
        @QObject::connect: Incompatible sender/receiver arguments
        QNetworkReplyImpl::finished() --> MainWindow::updateForm(bool)@
        error.

        I realize updateForm(bool error) function never calls. There are 2 connect functions to call the updateForm() . That connects don't work. In fact, There are 2 error because of the wrong 2 connects.

        @connect(http, SIGNAL(finished(QNetworkReply *)), this, SLOT(updateForm(bool)));
        connect(reply, SIGNAL(finished()), this, SLOT(updateForm(bool)));
        @

        mainwindow.h
        @
        ...
        private:
        Ui::MainWindow *ui;

        QNetworkAccessManager *http;
        QUrl url;
        QUrlQuery urlQuery;
        QNetworkReply *reply;@
        

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

        setWindowTitle(tr("Project Equation Editor"));
        
        http = new QNetworkAccessManager;
        //reply = new QNetworkReply;
        
        ui->outputLabel->setFrameShape(QFrame::StyledPanel);
        
        connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearForm()));
        connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(fetchImage()));
        
        connect(http, SIGNAL(finished(QNetworkReply *)), this, SLOT(updateForm(bool)));
        

        }

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

        void MainWindow::fetchImage()
        {
        qDebug() << "fetchImage";

        /*
        ui->clearButton->setEnabled(false);
        ui->updateButton->setEnabled(false);
        ui->equationTextEdit->setReadOnly(true);
        */
        
        url.setPath("/cgi-bin/mathtran");
        urlQuery.setQueryDelimiters('=', ';');
        urlQuery.addQueryItem("D", "3");
        urlQuery.addQueryItem("tex", QUrl::toPercentEncoding(ui->equationTextEdit->toPlainText()));
        
        url.setHost("mathtran.org");
        //reply = http->get(QNetworkRequest(QUrl(url.toString())));
        
        reply = http->get(QNetworkRequest(url));
        
        connect(reply, SIGNAL(finished()), this, SLOT(updateForm(bool)));
        
        //qDebug() << "fetchImage - reply:" << reply;
        

        }

        void MainWindow::updateForm(bool error)
        {
        qDebug() << "updateForm";

        if (!error) {
            QImage image;
        
            if (image.loadFromData(reply->readAll())) {
                QPixmap pixmap = QPixmap::fromImage(image);
                ui->outputLabel->setPixmap(pixmap);
        
                qDebug() << "updateForm - image.loadFromData";
            }
            qDebug() << "updateForm - !error (inside)";
        }
        
        qDebug() << "updateForm - !error (outside)";
        
        ui->clearButton->setEnabled(true);
        ui->updateButton->setEnabled(true);
        ui->equationTextEdit->setReadOnly(false);
        

        }

        void MainWindow::clearForm()
        {
        ui->outputLabel->setPixmap(QPixmap());
        ui->equationTextEdit->clear();
        }@

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JKSH
          Moderators
          wrote on 14 Oct 2013, 10:43 last edited by
          #4

          You can only connect a signal to a slot if they use the same parameters.

          Your code can't connect because your signal uses QNetworkReply* but your slot uses bool.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kingsta
            wrote on 14 Oct 2013, 14:46 last edited by
            #5

            Yes, You right. I nearly complete the program. When I do, I will write all of codes. I hope you never have that problem again.

            I wonder something that Is there any difference between 2 connects except function parameter [ updateForm(QNetworkReply*) and updateForm() ] ?

            @connect(http, SIGNAL(finished(QNetworkReply )), this, SLOT(updateForm(QNetworkReply)));

            connect(reply, SIGNAL(finished()), this, SLOT(updateForm()));@

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JKSH
              Moderators
              wrote on 16 Oct 2013, 14:54 last edited by
              #6

              Both signals are emitted when a HTTP request has finished.

              Note: Your slot is allowed to have less parameters than your signal. But, ALL of your slot's parameters must match the signal's first few parameters. The following connections are allowed.
              @
              connect(mySender, SIGNAL(mySignal(int, bool)),
              myReceiver, SLOT(bigSlot(int, bool)));
              connect(mySender, SIGNAL(mySignal(int, bool)),
              myReceiver, SLOT(mediumSlot(int)));
              connect(mySender, SIGNAL(mySignal(int, bool)),
              myReceiver, SLOT(smallSlot()));
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kingsta
                wrote on 17 Oct 2013, 07:18 last edited by
                #7

                Yes, I see what you say. Thank you.

                Here the codes. I hope nobody has no the problem in future.

                mainwindow.h
                @
                ...
                public slots:
                void fetchImage();
                void updateForm();
                void clearForm();

                private:
                ...
                QNetworkAccessManager *http;
                QUrl url;
                QUrlQuery urlQuery;
                QNetworkReply *reply;
                QImage equationImage;@

                mainwindow.cpp
                @
                ...
                void MainWindow::fetchImage()
                {
                qDebug() << "fetchImage()";

                url.setHost("www.mathtran.org");
                url.setPath("/cgi-bin/mathtran");
                url.setScheme("http"); // setting http protocol
                
                urlQuery.clear();
                urlQuery.setQueryDelimiters('=', ';');
                urlQuery.addQueryItem("D", "3");
                urlQuery.addQueryItem("tex", QUrl::toPercentEncoding(ui->equationTextEdit->toPlainText()));
                url.setQuery(urlQuery);
                
                //reply = http->get(QNetworkRequest(QUrl(url.toString())));
                
                reply = http->get(QNetworkRequest(url));
                
                connect(reply, SIGNAL(finished()), this, SLOT(updateForm()));
                
                ui->clearButton->setEnabled(false);
                ui->updateButton->setEnabled(false);
                ui->equationTextEdit->setReadOnly(true);
                

                }

                void MainWindow::updateForm()
                {
                qDebug() << "updateForm()";

                if (reply->error() != QNetworkReply::NoError) {
                    qDebug() << "Error in" << reply->url() << ":" << reply->errorString(); // for error code: reply->error()
                    return;
                }
                
                if (equationImage.loadFromData(reply->readAll())) {
                    QPixmap pixmap = QPixmap::fromImage(equationImage);
                    ui->outputLabel->setPixmap(pixmap);
                
                    qDebug() << "updateForm - equationImage.loadFromData";
                }
                else if(equationImage.isNull()){
                    qDebug() << "updateForm - equationImage.isNull";
                }
                
                ui->clearButton->setEnabled(true);
                ui->updateButton->setEnabled(true);
                ui->equationTextEdit->setReadOnly(false);
                

                }

                void MainWindow::clearForm()
                {
                ui->outputLabel->setPixmap(QPixmap());
                ui->equationTextEdit->clear();
                }@

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JKSH
                  Moderators
                  wrote on 17 Oct 2013, 08:06 last edited by
                  #8

                  You're welcome. Thank you for sharing your solution!

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0

                  1/8

                  11 Oct 2013, 22:11

                  • Login

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