Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Extreme confusing problem
Forum Updated to NodeBB v4.3 + New Features

Extreme confusing problem

Scheduled Pinned Locked Moved Solved General and Desktop
ressources imagressource
11 Posts 3 Posters 4.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcosta
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    is your png file in the same directory of the .qrc??

    Once your problem is solved don't forget to:

    • Mark the thread as SOLVED using the Topic Tool menu
    • Vote up the answer(s) that helped you to solve the issue

    You can embed images using (http://imgur.com/) or (http://postimage.org/)

    P 1 Reply Last reply
    0
    • M mcosta

      Hi and welcome to devnet,

      is your png file in the same directory of the .qrc??

      P Offline
      P Offline
      PandaBoy
      wrote on last edited by PandaBoy
      #3

      @mcosta
      Yes.And I tried creating a folder in the same directory of .qrc file and move png to that folder. It didn't work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mcosta
        wrote on last edited by mcosta
        #4

        Have you tried to use the resource icon in your real code??

        To show an Item in a GraphicsView you have to set correctly GraphicsScene rect and the view

        This code

        ui->label->setPixmap(QPixmap(":/images/image.png"));
        

        works well for me using the resource

        <RCC>
            <qresource prefix="/images">
                <file>image.png</file>
            </qresource>
        </RCC>
        

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        P 1 Reply Last reply
        0
        • R Offline
          R Offline
          Rondog
          wrote on last edited by
          #5

          Maybe the Q_INIT_RESOURCE(<qrc file name>) is missing from main?

          int main(int argc, char *argv[])
          {
              Q_INIT_RESOURCE(application);
              QApplication app(argc, argv);
             
              MainWindow mainWin;
              mainWin.show();
              return app.exec();
          }
          P 1 Reply Last reply
          0
          • M Offline
            M Offline
            mcosta
            wrote on last edited by
            #6

            @Rondog Q_INIT_RESOURCE is not required if you add the resource file in the .pro file

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply
            0
            • R Rondog

              Maybe the Q_INIT_RESOURCE(<qrc file name>) is missing from main?

              int main(int argc, char *argv[])
              {
                  Q_INIT_RESOURCE(application);
                  QApplication app(argc, argv);
                 
                  MainWindow mainWin;
                  mainWin.show();
                  return app.exec();
              }
              P Offline
              P Offline
              PandaBoy
              wrote on last edited by
              #7

              @Rondog Thank you Randog, But it is not the problem.
              I think that this line might be unnecessary. But you brought this up, I have another question for this line.
              I have tried this even before I asked here. And when I add this line to my main.cpp, It told me " LNK2019 unresolved symbol".
              There is an example in Qt document using this line, and I had the exact same libraries included.

              Note:

              1. resource file has been included in .pro file.
              2. Q_INIT_RESOURCE(Ima); /* name of my qrc file is Ima.qrc now*/
              1 Reply Last reply
              0
              • M mcosta

                Have you tried to use the resource icon in your real code??

                To show an Item in a GraphicsView you have to set correctly GraphicsScene rect and the view

                This code

                ui->label->setPixmap(QPixmap(":/images/image.png"));
                

                works well for me using the resource

                <RCC>
                    <qresource prefix="/images">
                        <file>image.png</file>
                    </qresource>
                </RCC>
                
                P Offline
                P Offline
                PandaBoy
                wrote on last edited by
                #8

                @mcosta Yes, I have. It doesn't work.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcosta
                  wrote on last edited by
                  #9

                  @PandaBoy could you attach your project? (the whole project directory)

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rondog
                    wrote on last edited by
                    #10

                    The unresolved linker error will occour if the name inside the macro Q_INIT_RESOURCE cannot be found.

                    I was not aware that this wasn't required, I tried it and sure enough it worked without it. It is interesting that when you did add it you ended up with a link error which means it can't be loaded (I have always added this line inside of main and get this error when I don't set the name properly).

                    From a sample program I have the following (that does work):

                    // qrc file =====================
                    <!DOCTYPE RCC><RCC version="1.0">
                    	<qresource prefix="/gui">
                    		<file>autocapture.png</file>
                    	</qresource>
                    </RCC>
                    
                    // pro file =====================
                    // note:  I put all the resources in a folder called 'res'
                    RESOURCES += res/autocapture.qrc
                    
                    // usage example =====================
                    	d_start_button->setIcon(QIcon(":/gui/autocapture.png"));
                    

                    A couple of observations that might be helpful.

                    The resources line in the .PRO file ...

                    RESOURCES += \
                    Ima.qrc
                    

                    ... might be a problem. Why not this instead:

                    RESOURCES += Ima.qrc
                    

                    The .qrc file is missing the first XML identification line (i.e. '<!DOCTYPE RCC>' ). Maybe the file is not recognized as a resource file without this line?

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mcosta
                      wrote on last edited by
                      #11

                      Hi,

                      <!DOCTYPE RCC> is not needed.

                      You have to add Q_INIT_RESOURCE when you want to load resources not embedded in your application.

                      I'm not sure to understand; the simple icon example works or not??
                      Your app with QGraphicsScene??

                      Once your problem is solved don't forget to:

                      • Mark the thread as SOLVED using the Topic Tool menu
                      • Vote up the answer(s) that helped you to solve the issue

                      You can embed images using (http://imgur.com/) or (http://postimage.org/)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved