[SOLVED] Download and Update a Qt Program on Linux



  • Hi everybody

    I am trying the programming an update system for my qt program.

    void MainWindow::updateDownloaded()
    {
        #ifdef Q_WS_WIN
            QString fileName = QString("Updater-%1.exe").arg(VERSION);
        #endif
        #ifdef Q_OS_LINUX
            QString fileName = QString("Updater-%1.run").arg(VERSION);
        #endif;
        qDebug()<<"One update has been downloaded."<<endl;
        QFile file(fileName);
        if(file.open(QIODevice::WriteOnly))
        {
            file.write(this->downloader->downloadedData());
            #ifdef Q_OS_LINUX
                file.setPermissions(QFile::ExeOther|QFile::ExeOwner|QFile::ExeGroup|QFile::ReadUser|QFile::ReadOther|QFile::ReadGroup|QFile::ReadOwner|QFile::WriteUser);
            #endif;
            QProcess *process = new QProcess(this);
            qDebug() << QDir::currentPath()+QDir::separator()+fileName<<endl;
            connect(process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(processErrorOccured(QProcess::ProcessError)));
            process->start(QDir::currentPath()+QDir::separator()+fileName);
    
        }
        delete this->downloader;
    
    }
    
    void MainWindow::processErrorOccured(QProcess::ProcessError err)
    {
        switch(err)
        {
        case QProcess::FailedToStart:
            qDebug()<<"Failed to start"<<endl;
            break;
        case QProcess::Crashed:
            qDebug()<<"Creached"<<endl;
            break;
        case QProcess::Timedout:
            qDebug()<<"Timedout"<<endl;
            break;
        case QProcess::WriteError:
            qDebug()<<"WriteError"<<endl;
            break;
        case QProcess::ReadError:
            qDebug()<<"ReadError"<<endl;
            break;
        case QProcess::UnknownError:
            qDebug()<<"UnknowError"<<endl;
            break;
        }
    
    }
    
    

    But I get "failed to start" error. When I try to run downloaded updater by clicking, program starts as expected. Program has right permissions to execute.



  • Maybe close the file after you write to it and before you try to start the QProcess.



  • Thank you mchinand. It works now.



  • Great! Just curious, how do you create the updater executables? Are they binary diffs between the versions?



  • Actually dll files and modules that changed or removed and update script. I will combine all of them in a single executable.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.