[debug/qrc_fontawsome.cpp] Error 1
-
I am working on a project, where I am supposed to add a font awesome to a pushbutton. To this end, I have downloaded the font awesome otf files for Desktop and put the folder into my project folder. Then, I added the "Font Awesome 5 Free-Regular-400.otf" file to the resource file. The following code is the code I have written to add a font awesome to a push button, but I got the error:
[debug/qrc_fontawsome.cpp] Error 1.
I would appreciate if someone could help me.The pro file:
QT += core gui RESOURCES += fontawsome.qrc greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = fontAwsome2 TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ dialog.cpp HEADERS += \ dialog.h FORMS += \ dialog.ui RESOURCES += \ fontawsome.qrc
dialog.cpp:
#include "dialog.h" #include "ui_dialog.h" #include <QFontDatabase> #include <QFont> #include <QPushButton> Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); QFontDatabase::addApplicationFont(":/Font Awesome 5 Free-Regular-400.otf"); QFont font; font.setFamily("FontAwesome"); font.setPixelSize(32); QPushButton *button = new QPushButton(this); button->setFont(font); button->setText("\uf083"); } Dialog::~Dialog() { delete ui; }
The code I have written in the resource file is shown in the picture bellow :
-
There is for sure another error message above the lines you posted. Is the file you want to add in the correct directory?
-
@Christian-Ehrlicher Thank you for reply. The directory of the otf file that I want to use is:
F:\qt codes\fontAwsome2\fontawesome-free-5.15.1-desktop\otfs
This file exists in my project folder. -
This is working fine for me:
main.cpp
#include <QtCore> int main(int argc, char **argv) { QCoreApplication app(argc, argv); if (QFile::exists(":/my.otf")) qDebug() << "File exists"; else qDebug() << "File does not exist"; return 0; }
tmp.qrc:
<RCC> <qresource prefix="/"> <file alias="my.otf">Font Awesome 5 Free-Regular-400.otf</file> </qresource> </RCC>
Compiled with
qmake -proejct qmake make
The file is from https://github.com/FortAwesome/Font-Awesome/blob/master/otfs/Font Awesome 5 Free-Regular-400.otf
-
@Christian-Ehrlicher I downloaded the file from the link you provided and put it into my project folder. Also I wrote your suggested code and got "File exists".
Now I got no errors, but I got the following result:The unicode I used is from here
I changed the code in the resource file as you posted:
<RCC> <qresource prefix="/"> <file alias="my.otf">Font Awesome 5 Free-Regular-400.otf</file> </qresource> </RCC>
Also, I updated my cpp file as your posted code:
#include "dialog.h" #include "ui_dialog.h" #include <QFontDatabase> #include <QFont> #include <QPushButton> Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); QFontDatabase::addApplicationFont(":/my.otf"); QFont font; font.setFamily("FontAwesome"); font.setPixelSize(32); QPushButton *button = new QPushButton(this); button->setFont(font); button->setText("\uf083"); } Dialog::~Dialog() { delete ui; }
-
I don't know what symbol is behind "\uf083" nor do I know if the font contains this symbol.
-
@Christian-Ehrlicher The unicode " f083" is from here. This is the unicode for camera.
The code I posted above is from here.
I am supposed to have something like this:
-
I can't see what's going wrong here. My only idea would be that the symbol is not available but I can't test it.
If you think this is a Qt bug please open a bugreport at https://bugreports.qt.io/edit: I did some more testing and would guess the symbol is not in the otf file - see http://prntscr.com/vbba17 - only a few icons are shown.
-
Ok, it's in Font Awesome 5 Free-Solid-900.otf in the free part available from https://fontawesome.com/download
-
@Christian-Ehrlicher Thank you so much for helping. I downloaded Awesome 5 Free-Solid-900.otf from the link you provided, but stilI got the picture bellow:
I also downloaded the svg file from here, and I got the same output!
-
It is working fine for me when I add
Font Awesome 5 Free-Solid-900.otf
to the resource file and load the font from there.
Don't know what you want with the svg though. -
@Christian-Ehrlicher Could you please send me your code, if its possible? Thanks.
-
@nanor I already posted my code above, simply replace the filename for the otf file.
-
@Christian-Ehrlicher I downloaded the fontawesome.ttf file from here and my code works fine now.
I don't know why Font Awesome 5 Free-Solid-900.otf didn't work for me, but the fontawesome used in the posted link project, works for my project.
I really thank you for you help. Your provided codes helped me a lot.
Best regards.