Void executes differently if called from other file.
-
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);
}@ -
Hi,
What is "void" ?
-
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. -
[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
-
Thanks alot for your knowledge.
Half day tryed many combinations but never touched symbols. -
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 :)