Results 1 to 18 of 18

Thread: Assisgn icon to my files with Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Assisgn icon to my files with Qt

    Hi. It's possible if i'm joining different's files with qt to assign one icon. My problem is when i join different files in one alone and i change in this alone the icon will be changed in all my files and then some files will be corrupted. In other words, someone know some way to assign one icon to one file. For example i'm using one qfile i can't assign to this one icon?
    Last edited by SirJonas; 12th December 2016 at 00:11.

  2. #2
    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: Assisgn icon to my files with Qt

    Maybe you can explain what you mean with "assign an icon"?

    Are you displaying files in your program somehow? Qt view with a QFileSystemModel perhaps?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Assisgn icon to my files with Qt

    Hi i'm trying to bind different files in one with Qt. But my problem is when i bind all files in one and change the resources of this one (the other's are corrupted). In other words, for example i change the icon in the output file(archivosalida) the other files are corrupted. So i was thinking to include my stub like resource because in my stub i add the other file's(all data) and their resources. So if i add my stub like resource when i change the icon in my single file, the resources of other's will not change. But i'm not sure if i can. I put the source of what things i'm trying.

    Binder:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QFileDialog>
    4. #include <QFile>
    5. #include <QTextStream>
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12. connect (ui->botonExaminar1,SIGNAL(clicked()),this,SLOT(examinar1()));
    13. connect (ui->botonExaminar2,SIGNAL(clicked()),this,SLOT(examinar2()));
    14. connect (ui->botonUnir,SIGNAL(clicked()),this,SLOT(juntar()));
    15. }
    16.  
    17. MainWindow::~MainWindow()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void MainWindow::examinar1()
    23. {
    24. ui->ejecutable1Texto->setText(QFileDialog::getOpenFileName(this,"Abrir archivo"));
    25. }
    26. void MainWindow::examinar2()
    27. {
    28. ui->ejecutable2Texto->setText(QFileDialog::getOpenFileName(this,"Abrir archivo"));
    29. }
    30. void MainWindow::juntar()
    31. {
    32. /** función para juntar los dos ejecutables **/
    33.  
    34. /* declaraciones */
    35. QFile archivoSalida;
    36. QFile *archivoEjecutable1;
    37. QFile *archivoEjecutable2;
    38. QFile *archivoStub;
    39. QByteArray tamano1;
    40. QByteArray tamano2;
    41. QByteArray tamano3;
    42. QByteArray trama(1024,'0');
    43. QString nombreEjecutable1;
    44. QString nombreEjecutable2;
    45.  
    46. /* inicializaciones */
    47. archivoEjecutable1 = new QFile();
    48. archivoEjecutable2 = new QFile();
    49. archivoStub = new QFile();
    50.  
    51. /* establecer nombres de los ficheros */
    52. archivoSalida.setFileName(QFileDialog::getSaveFileName(this,"Archivo de salida"));
    53. archivoEjecutable1->setFileName(ui->ejecutable1Texto->text());
    54. archivoEjecutable2->setFileName(ui->ejecutable2Texto->text());
    55. archivoStub->setFileName("./stubb.dat");
    56.  
    57. /* abrir ficheros */
    58. archivoSalida.open(QFile::WriteOnly);
    59. archivoEjecutable1->open(QFile::ReadOnly);
    60. archivoEjecutable2->open(QFile::ReadOnly);
    61. archivoStub->open(QFile::ReadOnly);
    62.  
    63. /* escribir en el fichero de salida los tres ejecutables */
    64. archivoSalida.write(archivoStub->readAll() + archivoEjecutable1->readAll() + archivoEjecutable2->readAll());
    65.  
    66. /* Convertir los tamaños a QString */
    67. tamano1.setNum(archivoStub->size());
    68. tamano2.setNum(archivoEjecutable1->size());
    69. tamano3.setNum(archivoEjecutable2->size());
    70.  
    71. /* Cojer los nombres de los ejecutables */
    72. nombreEjecutable1 = archivoEjecutable1->fileName().split(QDir::separator()).last();
    73. nombreEjecutable2 = archivoEjecutable2->fileName().split(QDir::separator()).last();
    74.  
    75. /* Crear la trama de datos */
    76. trama = tamano1 + "|@|" + tamano2 + "|@|" + tamano3 + "|@|" + nombreEjecutable1.toLatin1() + "|@|" + nombreEjecutable2.toLatin1();
    77. /* Escribir la trama en los últimos 1024 bytes del archivo de salida */
    78. archivoSalida.write(trama,1024);
    79.  
    80. /* Cerrar todos los ficheros */
    81. archivoEjecutable1->close();
    82. archivoEjecutable2->close();
    83. archivoStub->close();
    84. }
    To copy to clipboard, switch view to plain text mode 

    My Stub to run my other files in one.
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include <QFile>
    4. #include <QDir>
    5. #include <QProcess>
    6.  
    7. Widget::Widget(QWidget *parent) :
    8. QWidget(parent),
    9. ui(new Ui::Widget)
    10. {
    11. ui->setupUi(this);
    12. QDir directorio;
    13. QFile *archivoStub;
    14. QFile *archivoEjecutable1;
    15. QFile *archivoEjecutable2;
    16. QString trama;
    17. QString tamano1;
    18. QString tamano2;
    19. QString tamano3;
    20. QString nombre1;
    21. QString nombre2;
    22. archivoStub = new QFile();
    23. archivoEjecutable1 = new QFile();
    24. archivoEjecutable2 = new QFile();
    25. archivoStub->setFileName(QApplication::applicationFilePath());
    26. QFileInfo info1(QApplication::applicationFilePath());
    27. QString fileName=info1.fileName();
    28. archivoStub->open(QFile::ReadOnly);
    29. archivoStub->seek(archivoStub->size() - 1024);
    30. trama = archivoStub->read(1024);
    31. tamano1 = trama.split("|@|")[0];
    32. tamano2 = trama.split("|@|")[1];
    33. tamano3 = trama.split("|@|")[2];
    34. nombre1 = trama.split("|@|")[3];
    35. nombre2 = trama.split("|@|")[4];
    36.  
    37. archivoEjecutable1->setFileName(directorio.tempPath() + "/" + nombre1);
    38. archivoEjecutable1->open(QFile::WriteOnly);
    39. archivoStub->seek(tamano1.toInt());
    40. archivoEjecutable1->write(archivoStub->read(tamano2.toInt()));
    41. archivoEjecutable1->close();
    42. QProcess::startDetached(directorio.tempPath() + "/" + nombre1);
    43.  
    44. archivoEjecutable2->setFileName(directorio.tempPath() + "/" + nombre2);
    45. archivoEjecutable2->open(QFile::WriteOnly);
    46. archivoStub->seek(tamano1.toInt() + tamano2.toInt());
    47. archivoEjecutable2->write(archivoStub->read(tamano3.toInt()));
    48. archivoEjecutable2->close();
    49. QProcess::startDetached(directorio.tempPath() + "/" + nombre2);
    50. QProcess process;
    51. process.start("taskkill /f /im "+fileName);
    52. process.waitForFinished();
    53. process.waitForReadyRead();
    54. qDebug("test");
    55. }
    56.  
    57. Widget::~Widget()
    58. {
    59. delete ui;
    60. }
    To copy to clipboard, switch view to plain text mode 

    My question how i can avoid that i change resources of my other's file or my stub to let me change the resources in my single file( the file with all my application's).

  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: Assisgn icon to my files with Qt

    I have still no idea what you are asking for, but your code is obviously wrong.

    You read 1024 byte from the end but your writing never ensures it writes 1024 bytes.

    Any specific reason you are not using a standard archive format, e.g. ZIP?

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 3rd January 2016, 22:35
  2. Creating a list with icon and text in the center of icon
    By prophet0 in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2011, 03:03
  3. QDirModel (filter files, custom Icon, look)
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2009, 09:39
  4. Replies: 2
    Last Post: 12th October 2008, 14:42
  5. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03

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
  •  
Qt is a trademark of The Qt Company.