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. Void executes differently if called from other file.
Forum Updated to NodeBB v4.3 + New Features

Void executes differently if called from other file.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.4k 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.
  • Q Offline
    Q Offline
    Q139
    wrote on last edited by
    #1

    If called void from same file all executes , if called from other file signals and slots wont direct further executions.
    void is in qt http downloader example.
    "download.cpp here.":http://www.bogotobogo.com/Qt/Qt5_QNetworkRequest_Http_File_Download.php
    httpdownload.cpp under link and there is void being called, void executes but further signal , slots fail.

    calling fvoid from other ui .cpp file
    @
    void MainWindow::on_pushButton_clicked()
    {
    uurl = ui->lineEdit->text();

    HttpWindow obj;
    

    obj.downloadFile();

    ui->label_14->setNum(failed1);//2
    

    ui->label_9->setNum(finished1);
    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is "void" ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Q139
        wrote on last edited by
        #3

        Hi, this program uses http downloader example from qt but trying to control from other ui.

        @void HttpWindow::downloadFile()
        {

        url = uurl; //**********1
        
        
        
        QFileInfo fileInfo(url.path());//**********2
        QString fileName = fileInfo.fileName();//**********3
        if (fileName.isEmpty())//**********4
            fileName = "INDEXX.html";  //**********5
        

        /* if (QFile::exists(fileName)) {
        if (QMessageBox::question(this, tr("HTTP"),
        tr("There already exists a file called %1 in "
        "the current directory. Overwrite?").arg(fileName),
        QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
        == QMessageBox::No)
        return;

        }*/
        
        QFile::remove(fileName);//**********6
        
        file = new QFile(fileName);//**********7
        if (!file->open(QIODevice::WriteOnly)) {//**********8
            QMessageBox::information(this, tr("HTTP"),
                                     tr("Unable to save the file %1: %2.")
                                     .arg(fileName).arg(file->errorString()));
            delete file;
            file = 0;
            return;
        }
        
        progressDialog->setWindowTitle(tr("HTTP"));//**********9
        progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));//3//**********10
        downloadButton->setEnabled(false);//**********11
        
        // schedule the request
        httpRequestAborted = false;//**********12
        startRequest(url);  //1//**********13
        

        }@

        Code fails if called form other file,fail at lines below, if called from same file no problems.
        @
        void HttpWindow::startRequest(QUrl url)
        {
        reply = qnam.get(QNetworkRequest(url));//4//**********14
        connect(reply, SIGNAL(finished()),
        this, SLOT(httpFinished()));//**********15
        connect(reply, SIGNAL(readyRead()),
        this, SLOT(httpReadyRead()));//**********16
        connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
        this, SLOT(updateDataReadProgress(qint64,qint64)));//**********17
        }@
        Those lines execute but no signals return.
        If called from same file signals work.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          [quote author="Q139" date="1425070810"]
          calling fvoid from other ui .cpp file
          @
          void MainWindow::on_pushButton_clicked()
          {
          uurl = ui->lineEdit->text();

          HttpWindow obj;
          

          obj.downloadFile();

          ui->label_14->setNum(failed1);//2
          

          ui->label_9->setNum(finished1);
          }<< here obj is destroyed so it doesn't complete anything@

          [/quote]

          See my comment in your quoted code.

          If you want to call your download code from several places, you should rather create an object dedicated to that task

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Q139
            wrote on last edited by
            #5

            Thanks alot for your knowledge.
            Half day tryed many combinations but never touched symbols.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              If that answers your question, then please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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