I have now pretty much finished my application in Qt. I want to deploy it and among other things I would like to set the application information when someone right clicks the executable file and looks at the details.
The best source of information I found was this link: Setting application info in a Qt executable file on Windows
However, in Qt5, after creating a .qrc file and a prefix, I couldn't get it to work. If the .qrc file is edited outside of Qt, an unknown error always occurs when opening it inside Qt.
Can anybody please provide me with an working example? The way it's shown in the link above is exactly what I would like to do.
Thanks in advance!
Just create file "resources.rc" with Qt Creator "File"->"New File of Project.."->"General"->"Text file" or with any text editor in your project folder with this context:
IDI_ICON1 ICON DISCARDABLE "res/app.ico"
#include <windows.h>
#include "version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", VER_INTERNALNAME_STR
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR
VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
You should also have header file "version.h" in your project:
#ifndef VERSION_H
#define VERSION_H
#define VER_FILEVERSION 1,0,0,0
#define VER_FILEVERSION_STR "1.0.0.0\0"
#define VER_PRODUCTVERSION 1,0,0,0
#define VER_PRODUCTVERSION_STR "1.0\0"
#define VER_COMPANYNAME_STR "Your Organization"
#define VER_FILEDESCRIPTION_STR "CoolApplication"
#define VER_INTERNALNAME_STR "CoolApplication"
#define VER_LEGALCOPYRIGHT_STR "Copyright © 2010 Your Organization"
#define VER_LEGALTRADEMARKS1_STR "All Rights Reserved"
#define VER_LEGALTRADEMARKS2_STR VER_LEGALTRADEMARKS1_STR
#define VER_ORIGINALFILENAME_STR "coolapplication.exe"
#define VER_PRODUCTNAME_STR "CoolApplication"
#define VER_COMPANYDOMAIN_STR "example.org"
#endif // VERSION_H
Then in your *.pro file add
RC_FILE = file_prop_detail.rc
That is all. This aproach worked for me with Qt 5.4.
Related
My solution consists of an MFC App + Static library (name StatLib).
My StatLib contains resources (including icons), included in the "app.rc2" file in this way:
...
#include "C:\Project\LIBS\StatLib\StatLib.rc"
...
like described in this page.
I sort the icon ID's in this way:
App:
#define IDR_MAINFRAME 128
IDR_MAINFRAME ICON "res\MyApp.ico"
StatLib:
#define IDI_EM2D_ICON2 20018
#define IDI_EM2D_ICON3 20019
IDI_EM2D_ICON2 ICON "res\icon2.ico"
IDI_EM2D_ICON3 ICON "res\icon3.ico"
Like described in this page.
The problem is, the compiler automatically assigns to the exe the first icon it finds in the StatLib "icon2.ico" and not "MyApp.ico"
I have tried most of the suggestion regarding this issue to no avail.
I have created an Arduino project in CLion(version 2017.3.2) with Arduino plugin (version 1.2.3). I kept getting "undefined reference" during build.
My main Sample.ino file is:
#include <Arduino.h>
#include "Hello.h"
void setup() {
}
void loop() {
Hello::world();
}
and the Hello.h is simply:
#ifndef SAMPLE_HELLO_H
#define SAMPLE_HELLO_H
struct Hello {
static void world();
};
#endif //SAMPLE_HELLO_H
the Hello.cpp is
#include "Hello.h"
void Hello::world() {
}
and the CMakeLists.txt is:
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
set(PROJECT_NAME Sample)
project(${PROJECT_NAME})
set(${CMAKE_PROJECT_NAME}_SKETCH src/Sample.ino)
#include_directories(include)
include_directories(src)
#### Uncomment below additional settings as needed.
set(${CMAKE_PROJECT_NAME}_BOARD mega)
set(${CMAKE_PROJECT_NAME}_PORT /dev/ttyACM0)
set(mega.build.mcu atmega2560)
# set(mega.upload.protocol wiring)
set(mega.upload.speed 115200)
generate_arduino_firmware(${CMAKE_PROJECT_NAME})
All source files are under the folder src/,
Any suggestion to what have I missed?
I had the same problem and spent several hours to find a solution.
Arduino plugin uses arduino-cmake to build project. According to its documentation, to use generate_arduino_firmware command you should specify SKETCH or SRCS option.
If I define SKETCH option , I has no success to link additional files (hello.cpp).
So I try to use SRCS. Seems that if I define SKETCH and SRCS simultaneously, SRCS is be ignored. Another problem is when I specify src/sample.ino in SRCS option I have the same error.
So I do the following to compile the project successfully:
Renamed src/sample.ino into src/sample.cpp.
Commented out SKETCH and add SRCS option to list all source files:
set(${PROJECT_NAME}_SRCS src/sample.cpp src/hello.cpp)
Full CMakeList.txt is
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
set(CMAKE_CXX_STANDARD 14)
set(PROJECT_NAME Sample)
project(${PROJECT_NAME})
set(${PROJECT_NAME}_BOARD uno)
set(${PROJECT_NAME}_SRCS src/sample.cpp src/hello.cpp)
set(${PROJECT_NAME}_PROGRAMMER arduinoasisp)
set(${PROJECT_NAME}_PORT COM17)
set(${PROJECT_NAME}_AFLAGS -v)
generate_arduino_firmware(${PROJECT_NAME})
The Arduino support plugin uses arduino-cmake which has a bug causing your SRCS and HDRS to be erased when compiling a sketch.
You can read my bug report and proposed fix here. Basically you want to modify cmake/Platform/Arduino.cmake
Change line 1808 to avoid overwriting your sources
set(ALL_SRCS ${SKETCH_SOURCES})
set(ALL_SRCS ${ALL_SRCS} ${SKETCH_SOURCES})
Change line 1821 to recompile when a source changes
DEPENDS ${MAIN_SKETCH} ${SKETCH_SOURCES}
DEPENDS ${MAIN_SKETCH} ${ALL_SRCS}
I had that problem too.
Adding this to the CMakeLists made it work:
include_directories(${PROJECT_SOURCE_DIR})
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
file(GLOB HDR_FILES ${PROJECT_SOURCE_DIR}/*.h)
set(PROJ_SRC ${SRC_FILES})
set(PROJ_HDR ${HDR_FILES})
generate_arduino_firmware(${CMAKE_PROJECT_NAME}
SRCS ${PROJ_SRC}
HDRS ${PROJ_HDR}
)
I'm not sure if that's the best solution but it worked in my case.
The development for embedded system impose an other way to code.
In the goal to minimize size of my library named RF24Wave, I would adapt the structure of my main class.
The idea is to declare some functions only with the presence of certain #define during the inclusion of my library in main program.
The popular library, like MySensor use this way to minimize memory footprint.
So, I have two files for my library :
RF24Wave.h : header file which contain function declarations
#ifndef __RF24WAVE_H
#define __RF24WAVE_H
#include <arduino.h>
...
class RF24Wave
{
public:
/****** Common functions ******/
void begin();
#if !defined(WAVE_MASTER)
/****** Node functions ********/
void connect();
#else
/****** Master functions ******/
void printNetwork();
#endif
private:
bool synchronized = false;
}
RF24Wave.cpp: source file which contain function definitions
#include "RF24Wave.h"
void begin()
{
//Body of my function
}
#if !defined(WAVE_MASTER)
void connect()
{
//Body of my function
}
#else
void printNetwork()
{
//Body of my function
}
#endif
Secondly, I include this library in my main sketch named master.cpp, with #define WAVE_MASTER:
master.cpp: main sketch
#include <RF24.h>
#include <RF24Network.h>
#include <RF24Mesh.h>
#include <SPI.h>
#define WAVE_MASTER
#include <RF24Wave.h>
#include "master.h"
// Configure the chosen CE, CSN pins
RF24 radio(CE_PIN, CSN_PIN);
RF24Network network(radio);
RF24Mesh mesh(radio,network);
RF24Wave wave(network, mesh);
uint32_t displayTimer = 0;
void setup()
{
Serial.begin(115200);
wave.begin();
}
void loop()
{
wave.listen();
wave.printNetwork();
}
The goal is to include only master functions when #define WAVE_MASTER is defined in the main sketch.
However, during the compilation of my main sketch, I have a linking error
In function `main':
undefined reference to `RF24Wave::printNetwork()'
collect2: error: ld returned 1 exit status
*** [.pioenvs/uno/firmware.elf] Error 1
I compiled with PlaformIO Core 1.7.1 /Atom 1.13.0
Finally, the reason of this problem is the scope of #define.
The solution of this problem is added build flags to gcc-compiler !
If you use combo PlatformIO/Atom, you can add this line into this
config file platformio.ini :
build_flags = -D$NAME_DEFINE
In our case :
build_flags = -DWAVE_MASTER
After adding this line, the building seems work fine !
In addition, with this selective #define, my library has reduced footprint memory more than 10% !
Many thanks for your help.
If you add your library in the arduino IDE as it is described here it just consists in linking another project to your library functions. It's not a static library (see static and dynamic libraries). Then I think it's not necessary to worry about its size since the compiler will embed your library functions only if you use them.
Try opening any example (AnalogReadSerial), compile it. Then Sketch->Add a library->SPI. Compile it again, the size does not change. Try to call SPI.begin() in the setup function, the size increases. Add a call to SPI.setBitOrder(MSBFIRST);, the size increases again. Add another call to SPI.setBitOrder(MSBFIRST);, the size increases again, but not by the same amount since it contains only one setBitOrder definition and two calls to the setBitOrder function.
That's not exactly true for all libraries since some constructs could force the compiler to embed some code or allocate memory even if the variable is not used (see for instance volatile variables).
So regarding your size issue, you'd probably only need to use one #define MASTER, write the master code in setup and loop functions surrounded by #ifdef MASTER and the slave code surrounded by #else...#endif. The compiler will include the function definitions that both master or slave use.
So, with your answer, I found the solution !
The problem is the scope of #define. During the building, the first source code compiled is the main sketch ! So, it includes the correct #define WAVE_MASTER in RF24Wave.h of master.cpp. But, the compiler don't take this define into account of other source files. So, during the compilation of RF24Wave.cpp, #define WAVE_MASTER wasn't defined for this source file.
The solution consist to add an extra gcc-flag to define WAVE_MASTER for all source and header files.
With PlatformIO/Atom, it's possible in adding this line in config file platformio.ini
build_flags = -DWAVE_MASTER
Finally, your config file should look like this :
[env:uno]
platform = atmelavr
board = uno
framework = arduino
build_flags = -DWAVE_MASTER
With this solution, it is no longer necessary to add #define WAVE_MASTER in your header file, because this is the compiler which add it for you.
In addition, this optimization has been reduced more than 10% memory usage, because like this is a big class object, the compiler builded all functions. With selective define, the compiler will build only useful functions.
I'm creating a new library to control the keypad and LCD together. Most of the code seems to compile, but when it reaches the line where I define the LiquidCristal variable, it says:
'LiquidCrystal' does not name a type when creating a custom library
This is the extract of content of my LCDKeypad.h
// Include types & constants of Wiring core API
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#include "WConstants.h"
#endif
// Include LCD library
#include <LiquidCrystal.h>
The error is in this line:
private:
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 ); // <<-- Error
Alright, I was reading a lot and I found a very interesting article about this subject:
Including multiple libraries
It says that the compiler does not search for libraries that are not included in the sketch file. The way to hack this is to force the compiler to link them before loading your libraries, including, in my case LiquidCrystal.h in the sketch.
Let's say my library "LCDkeypad" requires LiquidCrystal.
My main program (sketch) needs to include LiquidCrystal in order to load it for my library "LCDKeypad".
Now, one interesting thing is using forward declaration, so in my LCDKeypad.h I will declare
"Class LiquidCrystal" but not include the library. I will do it in LiquidCrystal.cpp and in the sketch.
I hope this is clear.
There are two ways of doing it
If you are writing your own code Just create header file .h extension and relevant c code as name_c.While adding into main program, you need to specify header file name in double quotes.
code:
#ifndef LCD_H
#define LCD_H
//Declaration of variable /functions
#endif
If you are trying to download from link. Then you need paste the code into D:\arduino\arduino\libraries
Error problem:
overlapping of multiple declaration of variable.
overlapping of library functions
I am using Qt 4.5 in Windows XP. My pro file has the variable VERSION = 1.0. Now i need to read this variable and get its value (1.0) from the source code. So that I don't have to maintain another variable for version inside my source code. I just read from the pro file and update it. So that the value remains consistent all over my project. Is it possible? Any pointers regarding this are welcome..
Use somethings like this:
DEFINES += VERSION=\\\"$$VERSION\\\"
This will define a macro that you can use in C source code. Get rid of the backslashes and quotes if you want a number, not a string.
I'll elaborate on this a bit.
In the YourApp.pro:
VERSION = 0.0.0.1
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
In the main.cpp:
#include <QApplication>
QCoreApplication::setApplicationVersion(QString(APP_VERSION));
Wherever else in your sources, e.g. in the imaginary controller.cpp:
#include <QApplication>
QString yourAppVersion = QCoreApplication::applicationVersion();
somehow, when I tried qDebug() << QString(APP_VERSION); in a class.cpp not in main.cpp. has an error "C2065" APP_VERSION: undeclared identifier". but when I tried in main.cpp that worked.