So far I have worked in the console and a few days ago decided to try the QT GUI.
I downloaded the QT SDK , install it, adjust the location of QT and
set up the PATH Environment Variable -> per the instructions on the site.
I opened a new Qt4 project in Code:: Blocks-in and it seemed that everything was OK.
There is by default an example:
#include <QApplication>
#include <QFont>
#include <QPushButton>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
Started it an it was all OK.
After that I went to a tutorial on the official site and there is a final example.
Some kind of simple game.I have done copy-paste of all .h and .cpp files and then put
them in current project to see how it works but then problems arise.
Code::Blocks does not recognize some classes.
For example :: #include QTimer : No such file or directory
#include QRect : No such file or directory
I uninstall QT and re-installed and configured everything again but the problem does not go out.
These classes are not working nor in the default example ::
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QTimer> does not have real purpose , just for illustration
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
ba\107\main.cpp|4|QTimer: No such file or directory|
||=== Build finished: 1 errors, 0 warnings ===|
I dont now how much classes don work properly , this is just some of them.
Not to reveal hot water for days on google looking for a solution, maybe for some of you
, this is a bizarrely easy problem.
Thanks
You need to either spend time monkeying with the default include search path, or else just provide a more explicit path the header you want to include. I was able to reproduce your problem with Code::Blocks 10.05 (with bundled gcc) on Windows XP/32 and a previously installed Qt 4.6. Here is the slightly changed version of your code that I was able to build without any problem:
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QtCore/QTimer>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
Take a look in your Qt install directory. You'll be able to see the include directory, and where all the headers are within it if you run into this problem with any other headers. It looks like the Code::Blocks projects sets up the QtGui directory as an include search path by default, which is why you didn't need to explicitly mention it for including QPushButton and whatnot.
Code::Blocks is only an IDE not a Compiler/Linker toolchain, so it is not Code::blocks that cant find the files, you have simply not configured your project to use them.
"No such file or directory" is a pre-processor error message; you still have to tell the compiler where to find your third-party header files. Moreover when it comes to linking, you will need to tell the linker where to find the libraries.
Whenever you have an #include <blah> (with angle bracktes <>) the compiler looks in the default include path. You need to put the Qt include directory into the include path for your project. I'm not sure how this is done in Code::Blocks. It's probably somewhere in the project settings.
Related
I have a Qt Widget project that I created using QtCreator and Qt version 5.15.2 to which I'm trying to add the QtVirtualKeyboard as matchbox-keyboard I've already tried using stays under the application when it's in fullscreen mode.
However I'm having trouble getting it to work as it's not appearing at all at the moment. This is how I've tried adding it
Main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
MainWindow w;
//w.showFullScreen();
w.show();
return a.exec();
}
I've tried adding QT += qtvirtualkeyboard or QT += virtualkeyboard in the .pro file but it just gives me an error saying "unknown module"
How can I add the virtual keyboard to the project?
You will need to make sure that the QtVirtualKeyboard library is selected during the installation process.
Also, I would recommend you that you start using cmake for Qt applications as Qt has officially dropped qmake since the release of Qt 6.
It is not to say that you cannot use it, but you will get better support and results by using an actively developed build system rather than an abandoned.
I am programming with Qt Creator on a Mac (High Sierra 10.13.4). My projects seem to spontaneously break after a few days of work.
The linker error given is: "symbol(s) not found for architecture x86_64".
There is nothing wrong with the code - I open, run, close, and reopen projects and they are suddenly broken. I have also tested this with Qt's provided examples, to the same effect. I can copy-paste the code to a new project and compile it with no problem, but it will eventually do the same thing again.
I have attempted deleting the whole debug output folder of the project to give it a fresh start, but it did not make a difference. Same error.
Has anyone had this issue with QtCreator before? Is there a solution?
I have looked up a lot of very similar questions on here, but they all seem to be errors with the code. Just in case it's the same with me, this is all my code:
//main.cpp
#include "display.h"
#include "frame.h"
#include <QApplication>
int main(int argc, char * argv[])
{
QApplication a(argc, argv);
Display w;
w.show();
return a.exec();
}
Display.h & Frame.h are auto-generated.
//display.cpp
#include "display.h"
#include "ui_display.h"
#include "frame.h"
Display::Display(QWidget *parent) : QMainWindow(parent), ui(new Ui::Display)
{
ui->setupUi(this);
QWidget * f = new Frame(this);
setCentralWidget(f);
}
Display::~Display()
{
delete ui;
}
Frame.cpp last:
#include "frame.h"
#include "ui_frame.h"
Frame::Frame(QWidget *parent) : QFrame(parent), ui(new Ui::Frame)
{
ui->setupUi(this);
}
Frame::~Frame()
{
delete ui;
}
It is not that the linker error is as given. There's way more to it, and you're not including the meat of the message that actually carries meaningful information allowing to debug this issue. Your problem is possibly with the project becoming internally binary-incompatible, and qmake build system not catching onto it. The issue has nothing to do with Qt Creator. The build is done by qmake and make. You'll see those problems if you build from the command line - which I highly advise you to do.
Assuming the sources are in /Users/mycaptain/src/myproject, and that you're using Qt from macports, proceed as follows in terminal:
$ mkdir ~/src/build-myproject
$ cd ~/src/build-myproject
$ /opt/local/libexec/qt5/bin/qmake ../myproject
$ make
The thing is I am new to Qt, above at all, I am even more new to using frameworks. It is first time that I am using Qt framework for developing GUI for my end-semester programming project as Electrical Engineering Student.
But after installing Qt v5.6, when I made a project and compiled it then I got this frustrating error.
It's quite simple:
Do not use <QtModule/QClass> includes: they hide project misconfiguration and delay errors until linking.
After making sure that the .pro file contains relevant modules, you must re-run qmake and build the project. Or simply delete the entire build folder: this will force qmake to run again.
QCoreApplication cannot be used with widgets. Use QApplication instead.
Your program can look as follows:
#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QPushButton button("Hello, World!");
QObject::connect(&button, &QPushButton::clicked, &app, &QCoreApplication::quit);
button.show();
return app.exec();
}
The .pro file is very simple:
QT = widgets
TEMPLATE = app
TARGET = MyExample
SOURCES = main.cpp
I have installed Qt Creator with the msvc2017_64 binary. I also installed the Qt add-in for VS2017. I can create a QtGuiApplication without any problems, but when i try to compile it, many errors appear. I listed them here, on pastebin, because I cannot add this many characters to Stackoverflow. I'm sorry for that.
Do I need any essential packages for this? I installed C++ for VS2017 ofc. I also included the QtPath in the Qt VS Tools menu.
I did not edit the files since project creation and compiling fails due to errors.
EDIT: This problem is solved here. But not only the Errors form Pastebin exist, also the one following in the QtGuiApplication.h
QtGuiApplication.h: (Errors marked as comments)
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication1.h" //This could not be found
class QtGuiApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication1Class ui; //Ui namespace does not exist
};
QtApplication.cpp:
#include "stdafx.h"
#include "QtGuiApplication1.h"
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
main.cpp:
#include "stdafx.h"
#include "QtGuiApplication1.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication1 w;
w.show();
return a.exec();
}
I solved this problem myself!
The Qt add-in creates the Project with the Windowns 8.1 SDK, you need to retarget it to the Win 10 SDK to get the compile Errors from the QtGuiApplication.h away. Even if the 8.1 SDK is installed. Seems like a bug.
The solution was quite simple to me, just unload and then reload the solution from Solution Explorer!
This will clear all c++ compiler errors! Don't know why ...
I built a custom Qt5 for msvc2012 using BlueGo.
I was reading the examples and they show this:
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(320, 240);
window.show();
window.setWindowTitle(
QApplication::translate("toplevel", "Top-level widget"));
return app.exec();
}
Problem is, QtGui for me is actually a directory and not a file so it cannot be included. I'm using the include files under /qtbase/include/. Am I doing something wrong?
The QtGui header actually exists and simply includes all headers from the QtGui module. You can find it inside the QtGui directory. The compiler is able to find it because the QtGui directory is specified in the include paths. In other words, it's the same as:
#include <QtGui/QtGui>
It's a terrible practice to include the QtGui header though. You should only include what you actually use, otherwise compilation times will increase for no good reason. However, for quick tests and such, it's quite handy.
I know it is a bit late time now but you can do it like this:
add the gui module and widgets in the pro file :
QT += widgets core gui
And by replaging the include files,
replace
#include <QtGui/QWidget>
#include <QtGui/QApplication>
with
#include <QWidget>
#include <QApplication>
The compiler should recognize it.