Results 1 to 18 of 18

Thread: Assisgn icon to my files with Qt

  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,
    _

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

    Default Re: Assisgn icon to my files with Qt

    ok i change that:
    Qt Code:
    1. QByteArray trama(1024,'0'); -> QByteArray trama;
    2. archivoSalida.write(trama,1024); -> archivoSalida.write(trama):
    To copy to clipboard, switch view to plain text mode 

    But anyways i want to assign some icon to my file ArchivoSalida or some way that my other exe files will not be affected when i change the icon for example of my file archivosalida ( archivosalida is the file that contain all my exe files) And if i change the icon in this file, change me the resources in all my files and will be corrupted. So i was trying some way to avoid to change the resource of these files.

    My questions are:
    The first thing: i can include a resource file at the content of my file. And if this could be useful to assign one icon to my file archivosalida.
    Second: If it is not possible i can put my executables files like resources to avoid that they are corrupted.
    The problem is this:
    When i get file ArchivoSalidam and i change the icon of this file, the all files inside of archivosalida will change their resources and many will be corrupted. So someway to avoid that with code?¿ or not possible.


    Added after 1 15 minutes:


    If i change this:
    QByteArray trama(1024,'0'); -> QByteArray trama;

    I get this error:
    045de49043.png

    the strange thing i can join files of 100 MB or without any limit using one trama of 1024 bytes¿? LOL
    Last edited by SirJonas; 13th December 2016 at 19:05.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Assisgn icon to my files with Qt

    Ordinary files do not have "resources" and don't have icons. Your operating system (Windows, I assume) associates an icon with a file extension, and will display this icon in Explorer next to each file with the same extension. For example, it displays a "document" icon next to the name of every Microsoft Word document that has the .doc, .docx, etc.

    Executable files (.exe) can have an icon resource linked into them when the .exe file is created. Explorer will display this icon in the file list and will use it for the desktop link when you create a shortcut.

    Your "archivoSalida" file is not an executable file; neither are your "archivoEjecutable" files. They are ordinary binary files and do not contain either "resources" or "icons".

    When i get file ArchivoSalidam and i change the icon of this file, the all files inside of archivosalida will change their resources and many will be corrupted.
    The code you have posted contains no references to icons at all, so I have no idea what you are actually doing when you say you "change the icon of this file".
    Last edited by d_stranz; 13th December 2016 at 19:17.
    <=== 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.

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

    Default Re: Assisgn icon to my files with Qt

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

    One question about this. in trama i'm writting this:
    trama = tamano1 + "|@|" + tamano2 + "|@|" + tamano3 + "|@|" + nombreEjecutable1.toLatin1() + "|@|" + nombreEjecutable2.toLatin1();

    This contains different strings maybe can exceed more than 1024 bytes¿??? one string can be more weighty than 1024 bytes?¿

    How you recommend me include the size of my trama and my trama to be read for my stub. I can use qdatastream but like i'm using qfile seek i dont know if i could do both things. Anyways i think with qdatastream i can repeat the same thing that i'm trying to do and include the size of my trama.


    Added after 1 32 minutes:


    The more strange things the program only works when i compile since linux with gcc of linux. If i try with mingw of windows or something dont work.


    Added after 5 minutes:


    when i say How you recommend i'm trying to say if you know other way. But yeah i understand what you say. But in my string i only include the number's of my different files and names. I dont know if this can exceed more than 1024 bytes probably yes. Anyways i know more ways. But like i said before i dont know why the stuff works fine when i compile my binder in linux stub can be compiled in any operating system. But when i compile my binder in windows the program doesnt seem's to work.
    Last edited by SirJonas; 16th December 2016 at 00:33.

  8. #8
    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

    You could write the meta data to the beginning of the file, when you also know how long the meta data itself is.

    But really, not just use a standard container format like ZIP and get everything for free?

    Cheers,
    _

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

    Default Re: Assisgn icon to my files with Qt

    i'm trying to do a easy binder to join different files not for compressing. If i use zip i'm compressing my files. I can do once time and i get one single file. This is i'm trying. This is easy example using qfile seek but i dont know if it is better to use qdatastream and order the data and then read this data i dont know. Anyways seem's not works the file when i bind however in linux works so i think the code not works fine because i tried the compilation in linux and when i run the file works like i did. But in windows when i compile not seem's to work. I dont know if i do cross-compiling will be useful. But i think it's not necessary this is a small application basic. So my first question was that if it is better to use qdatastream to order the content and then read it and make all like i'm doing now. And the other about this strange behaviour only works when i compile the program in linux.

    The first difference i'm seeing with linux i must to put absolute path for example if i have my stub in the same place of my program and i use relative path show me:
    QIODevice::read (QFile, "stubb.exe"): device not open
    Code:
    Qt Code:
    1. archivoStub->setFileName("stubb.exe");
    To copy to clipboard, switch view to plain text mode 

    So no problem i put the absolute path. But when i run the program bind files but doesnt seek the files and this doesnt do nothing. However if i compile my binder in linux bind files correctly and works in windows.
    And i think because some bug o error in windows for this the program doesnt seems to work in windows.
    The bug i'm refering is this:
    https://bugreports.qt.io/browse/QTBUG-52618

    In windows 7 doesnt show the message. But in windows 10 show me this message. Anyways when i bind files with compilation of linux works and when i do with windows doesnt work too? So i think is that.

    For this i was little confused.
    Last edited by SirJonas; 16th December 2016 at 12:00.

  10. #10
    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

    Quote Originally Posted by SirJonas View Post
    i'm trying to do a easy binder to join different files not for compressing. If i use zip i'm compressing my files.
    No, why?
    What you would get is an easy way to combine multiple files into one file.

    Quote Originally Posted by SirJonas View Post
    I can do once time and i get one single file.
    Which is what an archive format would do.

    Quote Originally Posted by SirJonas View Post
    This is i'm trying.
    The questions is why you are trying it yourself instead of just using a library for archives?

    Cheers,
    _

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

    Default Re: Assisgn icon to my files with Qt

    Because i saw open project of binders in perl, java, c++, python. But no one in Qt so i was trying to do one in Qt. and Why ¿? Because i have different applications and i want to run at the same time with .exe format not compressed file like anyone. But if you ask me about personal reason because i want to do open source binder/joiner of any type of file however my progress so bad like you can see. Anyways, i think is a bug for windows because when i compile my binder in windows and i run the application never seeks my files and etc.... But when i do in linux bind the files with compilation in linux bind perfectly and run fine. So or i'm idiot or something strange happen. So anyways with cross-compiling creating .exe since linux works but it's like a big shit because you must to do cross-compiling to make one easy ugly binder. So can be solved with cross-compiling and i get run my binder in windows but i can't say why my binder must to be compiled in linux to get that the program works and why when i compile in windows the program seem's not to work. i leave so then.

    But the program works fine only you must to compile the binder in linux. And i can't say why happen this. It's very very strange.
    And the other thing i must to take care with the size of my string can exceed 1024 bytes but i'm not inserting a big data to be a trouble. Anyways i can put one limit to avoid this problem. Because using qdatastream i dont know if it is a good idea. i leave so then.
    Last edited by SirJonas; 16th December 2016 at 15:06.

  12. #12
    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

    Quote Originally Posted by SirJonas View Post
    Because i saw open project of binders in perl, java, c++, python. But no one in Qt so i was trying to do one in Qt.
    I have no idea what "binders" are or why one would use some obscure custom format instead of a standard archive format, but if there is a C++ implementation then it is directly usabkle in a Qt program as Qt is a C++ framework.

    Quote Originally Posted by SirJonas View Post
    Because i have different applications and i want to run at the same time with .exe format not compressed file like anyone.
    I am not talking about compression, a ZP file, for example, doesn't need to use any compression.
    There are other archive formats that don't even have compression at all, e.g. Tar.

    Quote Originally Posted by SirJonas View Post
    But if you ask me about personal reason because i want to do open source binder/joiner of any type of file however my progress so bad like you can see.
    Ok, so this is a personal training exercise, you want to learn file handling and chose creating a custom archive format as your target.
    Fair enough.

    Quote Originally Posted by SirJonas View Post
    So anyways with cross-compiling creating .exe since linux works but it's like a big shit because you must to do cross-compiling to make one easy ugly binder. So can be solved with cross-compiling and i get run my binder in windows but i can't say why my binder must to be compiled in linux to get that the program works and why when i compile in windows the program seem's not to work. i leave so then.
    I doubt cross-compiling will change anything, if your program misbehaves during runtime.

    Quote Originally Posted by SirJonas View Post
    But the program works fine only you must to compile the binder in linux. And i can't say why happen this. It's very very strange.
    That's indeed very strange.

    Quote Originally Posted by SirJonas View Post
    And the other thing i must to take care with the size of my string can exceed 1024 bytes but i'm not inserting a big data to be a trouble.
    If you write your metadata at the beginning of the result file you won't have any restriction of its size.
    E.g. by first writing the length of the meta data.

    Quote Originally Posted by SirJonas View Post
    Because using qdatastream
    That's also an option for having no limit, the stream will write the length of the string in a similar fashion.

    Cheers,
    _

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

    Default Re: Assisgn icon to my files with Qt

    I have no idea what "binders" are or why one would use some obscure custom format instead of a standard archive format, but if there is a C++ implementation then it is directly usabkle in a Qt program as Qt is a C++ framework.
    -->
    peoples mostly using file splitter for split file that will be uploaded to hosting servers, because some hosting server have their maximum upload file size, this program can merge HJSplit’s splitted files.

  14. #14
    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

    If you are restoring a single file that has been splt into pieces, you don't need to bother with any additional data.
    Just read each partial file and write to the target in the correct order.

    Cheers,
    _

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

    Default Re: Assisgn icon to my files with Qt

    ok i know why doesnt work because i'm retard only for that. now i'm checking one solution to get my trama without limiting the space of my string.
    when you say: If you write your metadata at the beginning of the result file you won't have any restriction of its size.

    The problem i must to know the size of my trama to extract it. But if i dont know maybe i get some qassert or list out of range. So i was checking qdatastream or something like that for this reason. Anyways, i'm checking this you said me:

    If you write your metadata at the beginning of the result file you won't have any restriction of its size.
    E.g. by first writing the length of the meta data.


    And checking too qdatastream

    That's also an option for having no limit, the stream will write the length of the string in a similar fashion.
    But at the momenti didnt get a minimal example how would be. I'm trying.

  16. #16
    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

    [QUOTE=SirJonas;296208]The problem i must to know the size of my trama to extract it.
    QString has a method to get its length, QByteArray as well.

    When using a QDataStream it will also first write the length of the string, then the string, so that it know how far to read when reading the string.

    Cheers,
    _

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

    Default Re: Assisgn icon to my files with Qt

    yeah i can put the size of my string but after how i will read it? The only way is using qdatastream? Include me the content at first or at the end of my file?
    I proved but i get this error:
    1297780736
    QIODevice::read (QFile, "\Desktop\visual\build-binder-Qt_5_7_0_msvc2
    013_static-Debug\debug\sha.exe"): maxSize argument exceeds QByteArray size limit

    ASSERT failure in QList<T>:perator[]: "index out of range", file C:\Qt\Qt5.7.0
    \5.7\mingw53_32\include/QtCore/qlist.h, line 545

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    Last edited by SirJonas; 18th December 2016 at 15:15.

  18. #18
    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

    Quote Originally Posted by SirJonas View Post
    yeah i can put the size of my string but after how i will read it? The only way is using qdatastream?
    QDataStream is the easiest option.

    Alternatively using QFile::read()

    Quote Originally Posted by SirJonas View Post
    Include me the content at first or at the end of my file?
    It is easier at the beginning since you can just read, if you add your meta data to the end you will first need to determine the length, then jum ahead, then read the meta data, then just to beginning and start reading the content.

    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.