QT resource is missing - c++

I made a simple QT application that display a gif image only. Althought I created a qrc file to store my gif image and icon. Then I set icon for the widget using Qt creator. Then I load gif using following code:
Welcome::Welcome(QWidget *parent) :
QWidget(parent),
ui(new Ui::Welcome)
{
ui->setupUi(this);
QMovie *movie = new QMovie(":/icon/rc/login.gif");
movie->scaledSize();
ui->label->setMovie(movie);
movie->start();
}
I tried to run this in QT Creator and everything is fine.
Then, I try to run it directly (I copy all neccessary libraries to the folder offcourse) but it is missing both gif and icon image.
Please help me to solve this. I appreciate your answer. Thanks
This is my .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QSSHTool
TEMPLATE = app
SOURCES += main.cpp\
welcome.cpp
HEADERS += welcome.h
FORMS += welcome.ui
RESOURCES += \
qsshresource.qrc

I found the solution.
Firstly, add this line into .pro file to allow gif plugin to be loaded
QTPLUGIN += gif
Then, when deploying your application, beside neccessary libraries, copy the qgif.dll to directory:
<executable_dir>/plugins/imageformats/qgif.dll
And it is done :) Hope it can help someone.

Simple! I have the same problem!
For me i just clicked on Qt Menu->Build->Run qmake.
After this i clicked on Qt Menu->Build->Build Project "..." Ctrl + B
It works for me...

Related

QT Resource File - Images Not Showing When Running

I just upgraded to QT Creator 5.3 and created a brand new QT Widgets Application project and am using the Microsoft VC++ compiler. All I have is a resource file with "logo.png" added (which opens in QT if I double click it), and a label that I am trying to set the background image for. The problem is that no matter what I do I cannot get the image to show up when the program is running. The only way I can get it to show the image is by not using the resource file and instead map directly to the file (ex. "c:/blah/blah/logo.png")
Also, if I set the background image in the UI designer, the background shows up in the IDE but NOT when I run the program. I have tried probably 20+ variations of the code, including resource file aliases as well as adding the files to the project directly, and nothing seems to work.
I'm not sure if there is a step I am missing, or if perhaps there is something that I have to do to get the project to compile the image.
Resources.qrc
<RCC>
<qresource prefix="/">
<file>logo.png</file>
</qresource>
</RCC>
loginform.cpp
QPixmap pixmap = QPixmap (":/logo.png");
ui->label->setPixmap( QPixmap(pixmap));
Project.pro
OTHER_FILES += \
logo.png
RESOURCES += \
Resources.qrc
After countless hours of trial, error, and mostly frustration, I have been able to resolve this issue by simply running qmake.
To do this I just right clicked on the project and clicked "Run qmake" and suddenly the image errors (as well as a few others) were resolved!

Why doesn't my Qt application present a GUI when executed?

I have been given a C++/C code with a .pro file to compile in Qt (it is a large, messy code, so I would like to use Qt and the .pro file provided).
The code is intended to generate a GUI. I can compile it in Qt without any errors (on both Mac OS X 10.7.5 and Mac OS X 10.8), and I see the executable. However, when I click on it, nothing happens. When I run it the usual way via the command line nothing happens. Here are the run commands I'm trying:
./calc.app/Contents/MacOS/calc
exec ./calc.app/Contents/MacOS/calc (this one results in the output: [Process completed]).
In the .pro file (below), I do not see anything that seems to indicate I want a GUI. However, I read at the Qt help site that the GUI module does not need to be specified in the .pro file because it is included automatically. Perhaps I am misunderstanding something?
Are the any issues with my .pro file?
TEMPLATE = app
LANGUAGE = C++
TARGET = calc
VERSION = 3.1.0
CONFIG -= qt
CONFIG += warn_on
CONFIG += debug
#CONFIG += windows
CONFIG += console
DEFINES += IPMGEMPLUGIN
DEFINES += NOPARTICLEARRAY
!win32 {
DEFINES += __unix
}
GMS_CPP = ../GMS
GMS_H = $$GMS_CPP
DEPENDPATH +=
DEPENDPATH += .
DEPENDPATH += $$GMS_H
INCLUDEPATH +=
INCLUDEPATH += .
INCLUDEPATH += $$GMS_H
QMAKE_LFLAGS +=
OBJECTS_DIR = obj
SOURCES += main.cpp
include($$GMS_CPP/gms.pri)
I don't know anything about Qt, and of course none of us know anything about the specific application you're compiling - so the assistance I can give you may be woefully inaccurate.
However, this sticks out like a sore thumb:
#CONFIG += windows
CONFIG += console
A quick Google search indicates that Qt does indeed support console applications - that is, applications which do not create a GUI, but instead act as console / terminal / command-line tools. This appears to be the case with the one you're working with. Presuming the application even works, it likely expects input to be passed to it on the command line, and will produce output of some sort in response - but with this configuration, it will not create a GUI.
I recommend contacting the person who gave you this application for further support.
CONFIG -= qt basically means "The target is [not] a Qt application/library and [does not require] the Qt library and header files." You should delete that line. Source: http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#config
Also, it couldn't hurt to add QT += core gui. This is normally done for you automatically, but since you're having project file problems it couldn't hurt... Also, make sure your main.cpp's main method ends in return a.exec();, and that a is a QApplication instance (Qt 4.x) or a QGUIApplication instance (Qt 5.x). main.cpp should be a short function that creates the main widget or window, shows it, then starts the event loop.
If your project still doesn't work properly, I would highly recommend that you ditch the project file. In other words, I would download the OS X package for the Qt SDK, create a new project, then import your files into the new project. After that, I would pluck only the necessary lines from your old .pro file and put them in the new one until it works (specifically, I noticed you have some custom DEFINES += ...). However, all of this advice assumes the fault lies in the project file, not your code. ;-)

qtcreator tray icon under window does not show up when deployed

i'am trying to deploy a QT application made in QT Creator which goes back to system tray when closed.
I have made a svg tray icon, when i run it from QT Creator, either in debug and in release mode under Window 7, the tray icon shows up, but when i copy everything to another directory to make a distributable archive from it, the tray icon does not show up anymore.
Of course i search already for solutions, but everything i have found yet, i have made.
So what i have:
trayicon.svg file in project root
qrc file created, adding trayicon.svg into the resource files root
in project .pro file: RESOURCES += resources.qrc
copied binary + necessary dll's to target directory
copied QT plugins imageformats/* to target dir imageformats
added QApplication a(argc, argv); a.addLibraryPath(a.applicationDirPath()); to main.cpp
that is everything i found so far, but still the system tray icon is not showing up
What am i missing?
(current qt 4.8 + current qtcreator by the way)
#netrom
code in MainWindow : QMainWindow constructor:
trayIcon = new QSystemTrayIcon(this);
showAction = new QAction(tr("&Show"), this);
connect(showAction, SIGNAL(triggered()), this, SLOT(show()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(showAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
trayIcon->setIcon(QIcon(":trayicon.svg"));
trayIcon->show();
Create iconegines directory in your app directory (for example: c:\MyApp\iconengines).
Copy qsvgicon.dll to this new directory (for example: c:\MyApp\iconengines\qsvgicon.dll) from qt plugins directory (in my case it's c:\qt\5.4\mingw491_32\plugins\iconengines\qsvgicon.dll).
Copy QtSvg.dll to your app directory (for example: c:\MyApp\Qt5Svg.dll) from Qt bin directory (in my case it's c:\qt\5.4\mingw491_32\bin\Qt5Svg.dll).
P.S. I know I'm late, this answer is for those who will google same problem.
Again, way later for DuckDuckGo-ers:
If your icon is not in .svg you might need another solution. For my .ico system tray icon I had to copy <path-to-qt>\plugins\imageformats into the application folder. Actually only qico.dll was needed in that folder in my case, but you get my drift.

how open in eclipse ".pro File Editor"

i'm need in eclipse the qt and openCV library. i'm found the tutorial http://www.welding.iat.uni-bremen.de/cms/index.php?view=article&catid=14%3Aimage-processing&id=14%3Aa-tutorial-on-integrating-eclipse-qt-and-opencv&format=pdf&option=com_content&Itemid=24 where writen last step "
We make sure that the Advance Mode is selected, we create a New Variable (1) and we give the name LIBS to this variable (2)
selecting the Append as Assignment Operator.
We have to add the following content to the variable(2), -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux".
how my open last window so as double clicking don't open. Opens file where code
TEMPLATE = app
TARGET = ex1
QT += core gui
HEADERS += ex1.h
SOURCES += main.cpp \
ex1.cpp
FORMS += ex1.ui
RESOURCES +=
how my run it task?
sorry bad english.
If I understand correctly: Right click on .pro file and go to 'Qt Project Editor', if it is not there then you can use the text editor option (or something is wrong with your Eclipse Qt installation).

How to set application icon in a Qt-based project?

How do you set application icon for application made using Qt? Is there some easy way? It's a qmake-based project.
For Qt 5, this process is automated by qmake. Just add the following to the project file:
win32:RC_ICONS += your_icon.ico
The automated resource file generation also uses the values of the following qmake variables: VERSION, QMAKE_TARGET_COMPANY, QMAKE_TARGET_DESCRIPTION, QMAKE_TARGET_COPYRIGHT, QMAKE_TARGET_PRODUCT, RC_LANG, RC_CODEPAGE.
For Qt 4, you need to do it manually. On Windows, you need to create a .rc file and add it to your project (.pro). The RC file should look like this:
IDI_ICON1 ICON DISCARDABLE "path_to_you_icon.ico"
The .pro entry should also be win32 specific, e.g.:
win32:RC_FILE += MyApplication.rc
Verified in Linux (Qt 4.8.6) and Windows (Qt 5.6):
1) Add the icon file to your project folder;
2) In the main function call setWindowIcon() method. For example:
QApplication a(argc, argv);
a.setWindowIcon(QIcon("./images/icon.png"));
To extend Rob's answer, you can set an application icon for macOS by adding and modifying the following line onto your .pro file.
macx: ICON = <app_icon>.icns
Note that the ICON qmake variable is only meant to target macOS.
For Windows, use
RC_ICONS = <app_icon>.ico if you're attaching a .ico file
or RC_FILE = <app_icon>.rc if you want to attach your icon through a .rc file. (Be sure to add IDI_ICON1 ICON DISCARDABLE "myappico.ico" into the rc file. Indentation not mine.)
For further reading, see Setting the Application Icon.
For Qt5 on Windows, move your ico file to project folder and add this line to your .pro file:
RC_ICONS = myappico.ico
Offical link: https://doc.qt.io/qt-5/appicon.html
Now that Qt has upgraded to 5.0.1, there is new method to add an application icon. First, you need prepare a resource file, named as .qrc
1) Without Qt Designer, I assume there is a QMainWindow instance whose name is MainWin. You can use:
QIcon icon(":icon/app.icon");
MainWin.setWindowIcon(icon);
2) With Qt Designer, you can modify the property of QMainWindow. Choose icon resource from .qrc and insert it into the row of windowIcon.
The above method can be used in Qt4.7, Qt4.8.x.