Error with QT Creator - c++

Hello I am having build errors with QT Creator and I was wondering if someone knows why its making these errors. Thanks
main.cpp:
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsView>
int main(int argc, char *argv[]){
QApplication a(argc, argv);
//Create Scene
QGraphicsScene * scene = new QGraphicsScene();
//Creat Item To Put Into Scene
QGraphicsRectItem * rect = new QGraphicsRectItem();
rect->setRect(100, 50, 100, 100);
//Add Item To Scene aka buffer
scene->addItem(rect);
//add a view
QGraphicsView * view = new QGraphicsView(scene);
view->show();
return a.exec();
}
mygame.pro:
#-------------------------------------------------
#
# Project created by QtCreator 2017-05-03T12:14:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mygame
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
HEADERS +=
Compile Output:
Error while building/deploying project mygame (kit: Desktop Qt 5.8.0 MSVC2015_64bit)
When executing step "qmake"
I am not sure what is making these errors(words words and more words for more detail so "It looks like your post needs some more detail" will go away... its not going away so I shall continue typing until it chooses to do so but it looks like it is not going to any time soon. there we go).

Look at the Compile Output tab. If needed you can also run qmake on the command prompt.
Another helpful way to fix bizarre qmake errors is to get a fresh Project settings in Qt Creator.
Close Qt Creator, delete the .pro.user file, and reopen Qt Creator with your project. This will force you to reconfigure your project with your Qt Version(s) Debug/Release, etc.
Hope that helps.

Related

Where do I put the QT5 clone in this project

This is my first time every using C++ so please go easy on me. I have about 7000 hours of Python experience so I'm not completely clueless. I'm trying to read the code written for the Collatinus software found here. collatinus. It seems that the initial file is this:
VERSION = "11.2"
DEFINES += VERSION=\\\"$$VERSION\\\"
DEFINES += MEDIEVAL
TEMPLATE = app
TARGET = collatinusd
INCLUDEPATH += . src
DEPENDPATH += .
DESTDIR = bin
OBJECTS_DIR= obj/
MOC_DIR = moc/
QMAKE_DISTCLEAN += $${DESTDIR}/collatinus
CONFIG += console
CONFIG -= app_bundle
CONFIG += release_binary
QT += core
QT -= gui
QT += xmlpatterns
QT += network
I've downloaded qt from qt and got the open source qt5. Now I cannot figure out where to put the file. I have tried putting it in the same folder as the above mentioned code. I have also tried putting in the folder marked src. In the src folder there are many files which use QT but it seems like the files are supposed to be taken out of the QT folder. For example in this file we have the syntax on line 28
#include <QDebug>
The QDebug file is in the QT folder. But when I put the qt folder in either the topmost folder or the src folder I get the error message:
fatal error: 'QtCore' file not found
#include <QtCore>
So the file structure is as follows:
/collatinus-daemon
collatinus.pro (and other files)
//src
flexion.cpp (and other files)
So where do I put the qt folder? Also, I renamed it qt from qt5 since the syntax had the line:
QT += core
###################
Ok, I've got the QT creator up and running. Here is the pro file
QT += network widgets
QT += core
QT -= gui
TARGET = Client_C11
VERSION = "1.0"
#CONFIG += console
#CONFIG -= app_bundle
CONFIG += release_binary
TEMPLATE = app
SOURCES += src/client_main.cpp
OBJECTS_DIR= obj/
MOC_DIR = moc/
unix:!macx:DESTDIR = bin
macx:{
# Commandes spéciales pour déployer l'application sur Mac.
# J'ignore s'il faut l'équivalent pour Linux ou Windows.
# Philippe. Octobre 2016
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8
ICON = collatinus_bw.icns
deploy.commands = macdeployqt Client_C11.app
QMAKE_EXTRA_TARGETS += deploy
}
Here are some screenshots of my folders:
And here is the error message I'm getting:
Here also is the code for the client main
#include <QCoreApplication>
#include <iostream>
#include <QtWidgets>
#include <QtNetwork>
class QTcpSocket;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString req = "";
if (argc > 1)
{
int i = 1;
while (i < argc)
{
QString suite(argv[i]);
req += " " + suite;
i++;
}
}
else req = "-?"; // pour afficher l'aide.
QTcpSocket * tcpSocket = new QTcpSocket();
tcpSocket->abort();
tcpSocket->connectToHost(QHostAddress::LocalHost, 5555);
QByteArray ba = req.toUtf8();
tcpSocket->write(ba);
tcpSocket->waitForBytesWritten();
tcpSocket->waitForReadyRead();
ba = tcpSocket->readAll();
tcpSocket->disconnectFromHost();
tcpSocket->close();
QString rep(ba);
std::cout << rep.toStdString();
a.quit();
}
I don't understand what I'm supposed to do with qmake and cmakelists
Where do I put the QT5 clone in this project
You don't :)
Qt installations up to 5.14 are not relocatable. That means that once Qt is installed, if you move it to another path, it'll break. Just don't mess with it: once installed, you leave it alone, and it'll work just fine.
Qt source code has to be built before it can be used. I presume that you downloaded the source code and want to stick it into the project and build the two that way. It's not designed to work that way at all.
Qt build requires several other tools to be installed (iirc python, ruby, perl), and other optional dependencies to get the full feature set, and if it fails for whatever reason, figuring it out is unnecessary effort initially. So it's best to start with pre-built Qt.
I've downloaded qt from qt and got the open source qt5. Now I cannot figure out where to put the file.
Downloading "qt" doesn't mean much, since everyone means something else by that. If you've downloaded the source code, then delete it - last thing you want is to mess with compiling Qt right now.
Normally, Qt is installed using an installer, so what you'd download is an executable installer, and use that to select the Qt components you want to install. On Windows, pick the mingw-based Qt version, since that also installs the build environment (compilers) if you don't have them already. Otherwise you'd use the MSVC-based version if you got MSVC installed on Windows.
On Unix, you'd want to install Qt using the "native" package manager - one that came with your linux distribution, or macports (really preferred) on MacOS.
Once Qt is installed, you'd use Qt Creator IDE to open the collatinus project (its .pro file). And everything will "just work" from that point onwards - it'll let you build it and run whatever executable targets it produced. Of course you can build from the command line, but for a beginner it's just an extra layer of complication and unnecessary.
In any case, the .pro file you refer to would be processed by qmake to generate the build system that builds the project. qmake itself is the means you use to select what Qt version you build with: there's one qmake per each Qt installation. So, after qmake has ran, you'd make the thus-configured build, and there'll be no problems with finding Qt headers. It's the job of qmake in that case to set everything up so that the compiler will be told where to find Qt. You are not expected to have to mess with it manually.
If there's a CMakeLists.txt file in the project, you'd probably prefer to use that instead of qmake, since cmake is a widely used tool with lots of knowledge available online, whereas qmake is now obsolete. Still, older projects may only supply a .pro file that needs to be used with qmake and not cmake.
Your question doesn't nearly provide enough detail for a more focused answer - please tell us exactly what you did, and what Qt elements you installed (whether using Qt Installer program, or using a unix package manager).

Qt 5.3. QtWidgets: No such file or directory #include <QtWidgets>

I want to compile Qt example. I get error QtWidgets: No such file or directory #include
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - does not help
QT += widgets - does not help
INCLUDEPATH += /opt/Qt/5.3/Src/qtbase/include/ - does not help
Qt 5.3. Ubuntu 14.04 x64.
You need to double check that you completed all these steps:
Module installed
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
You re-run the Qt 5 qmake.
Having said that, I would like to remind you that including the whole module is not a good idea as it includes all the widgets related things. Try to narrow it down to the headers that you really need.
As you noticed Qt directory structure changed between Qt4 and Qt5. QWidget header moved to a QtWidgets directory. Try adding
INCLUDEPATH += /opt/Qt/5.3/Src/qtbase/include/QtWidgets
If that does not help try finding the header manually using
find /opt/Qt/5.3/Src/qtbase/ -name QWidget
and and the directory it is in to INCLUDEPATH
Edit based on comment from Final Contest.
I agree that workarounds usually are a bad idea. To test where QT your installation looks for qt5 headers and libraries. Create a minimal project.
#include <QApplication>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget w;
w.show();
app.exec();
}
Generate a project and add QT += widget
/opt/Qt/5.3/Src/qtbase/bin/qmake -project
Project file
######################################################################
# Automatically generated by qmake (3.0) Thu Jul 10 13:05:17 2014
######################################################################
TEMPLATE = app
TARGET = so_qtwidgets
INCLUDEPATH += .
QT += widgets
# Input
SOURCES += main.cpp
Generate a make file
/opt/Qt/5.3/Src/qtbase/bin/qmake
The interesting parts widget flag adds:
In my case -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui to INCPATH
-DQT_WIDGETS_LIB to DEFINES variable.
-lQt5Widgets -lQt5Gui to libs.
The only part which should differ is the paths to QtWidgets and QtGui. If these a wrong the I would try reinstalling Qt.
Check what your .pro file looks like before you run "make". I found that the command "qmake -project" auto generated a .pro file that caused this same error. I now compiled my qt project via the following commands and the error went away:
qmake my_project.pro
make
This all looks very much like the wrong way round and I did have the same problem temporarily with 5.6 but the answer could be a whole lot simpler.
If you're loading a lot of examples you may arrive at the editor or whatever you were at last, first. If the example's been loaded for the first time it'll need to be 'configured' which is under the projects side-tab which should present you with 'Configure' rather than 'Build & Run'. That it doesn't always jump straight there is a flaw, but then so's the inclusion of examples with no support by default (Desktop OpenGL and iOS for two).
Until that's done it'll not resolve any dependencies outside the immediate project as the libraries used depend on which compiler/target is used (eg. MSVS, GNUCC, MinGW, 32/64bit).

Qt executable error- dll library

A Qt application which runs perfectly when executed from QtCreator, doesn't wont to run when I try to execute it from debug folder (without QtCreator). It asked for lots of .dll files and I downloaded them one by one,and added to debug folder.
Now I got the error:
The program can't start because libwinpthread-1.dll is missing from your computer.
Try reinstalling the program to fix this problem.
I can't find libwinpthread-1.dll anywhere on the internet. What did I do wrong?
The path to the executable is:
C:\Qt\Tools\QtCreator\bin\build-SimpleText1_3-Desktop_Qt_5_2_1_MinGW_32bit\Debug
The project file:
#-------------------------------------------------
#
# Project created by QtCreator 2014-04-04T14:29:48
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SimpleText1_3
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
CONFIG += console c++11
QMAKE_CXXFLAGS += -std=c++11
And main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
When you run your application in Qt Creator every thing is good but when you run your .exe file fro debug folder you get dll missing error. It`s True!
First set Qt Creator to Release mode. You must copy these dll & the folder to Release folder:
platforms --> Folder
icudt52.dll
icuin52.dll
icuuc52.dll
msvcp110.dll
msvcr110.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
Above dll are for Visual Studio compiler & only Core & GUI library.
Good Luck.
Ya Ali.
Go to the following Qt documentation link:
https://wiki.qt.io/Deploy_an_Application_on_Windows.
Follow the instructions precisely. I did not have to do the brut force approach. I did get a missing environment variable warning, but the bunding did work.
Be careful about release vs debug builds.

Qt Libraries cannot be found on Mac

I'm having issues setting up the Qt environment on Mac 10.9.1. If I just try to compile a C++ file with the standard g++ source.cpp -o output Then none of the Qt Libraries are found. For instance if I have
#include <QString>
Then I will get the error fatal error: 'QString' file not found
I have installed Qt 5.2.1 and added it to my PATH variable, so now when i make the project using qmake -project, qmake -spec macx-g++ and then make
I get the error saying that my version of Mac OSX is not supported. I have to use Qt for my college assignment, please can someone help me set this up.
Any help would be appreciated.
Mavericks is definitely supported by Qt 5. It is not supported by Qt 4 so far; trojanfoe made a typo in his comment (nomen est omen?).
Your mistake is using the wrong make spec. Qt 5 uses clang, not gcc. Thus the following works for me (without setting any paths):
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -project
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -spec macx-clang
make
You can have multiple Qt versions existing side by side, there's no reason to uninstall anything when you get a new Qt version installed.
A small self-contained example would be below. Put it in a simple folder. To build, do:
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -spec macx-clang
make
You do not want to regenerate the .pro file by invoking qmake with -project argument. The project generation is just to give you a simple skeleton, you're only supposed to do it as a convenience when importing third-party code.
Note that by definition if you use any visible GUI elements (windows, message boxes, etc), it's not a console application anymore as far as Qt is concerned.
# simple.pro
TEMPLATE = app
QT += widgets
# Creates a simple executable instead of an app bundle
CONFIG -= app_bundle
SOURCES += main.cpp
// main.cpp
#include <QApplication>
#include <QMessageBox>
int main(int argc, char ** argv)
{
// It is an error not to have an instance of QApplication.
// This implies that having an instance of QCoreApplication and QGuiApplication
// is also an error.
QApplication app(argc, argv);
QMessageBox::information(NULL, "Get This!", "Something's going on");
}

Qt - Quick 2 App from new project (main.qml file not found)

I didn't change anything in default qt creator app, so all should be ok. I created new project and tried to compile and run. Compile process ok, but after run, main.qml not found, so i see just black window without any interface (there should be hello world text).
qml1.pro
# Add more folders to ship with the application, here
folder_01.source = qml/qml1
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/qml1/main.qml"));
viewer.showExpanded();
return app.exec();
}
Console output after app run from creator:
QML debugging is enabled. Only use this in a safe environment.
file:///Users/Krab/projects/qtProjects/build-qml1-Desktop_Qt_5_1_1_clang_64bit-Ladění/qml1.app/Contents/Resources/qml/qml1/main.qml: File not found
Well I can build a application when the qml files are missing because they aren't processed or anything. So everything seems fine to the compiler.
But I would advise you to look in the directory: Users/Krab/projects/qtProjects/build-qml1-Desktop_Qt_5_1_1_clang_64bit-Ladění/qml1.app/Contents/Resources/qml/qml1/
To check if the QML files are located there.
Also where is you local qml file, is it in the project directory? Otherwise the builder doesn't have anything to export to the build directory.