Issues in new project from creation
-
Hello, I am new to QT Creator, and relatively new to C++. I am using QT Creator 4.11.0, on an Ubuntu laptop. I have successfully completed my first program for Linux using QT Creator. However, whenever QT creator creates a new empty project, there are already some issues. These issues don’t prevent compilation and running of the program, but they do create many warnings and I don’t know how to fix it. Here is what I am getting:
For every function in mainwindow.cpp it says: use of undeclared identifier “MainWindow”.
At the top of the window in a yellow bar it says Warning: The code model could not parse an included file, which might lead to incorrect code completion and highlighting. For example. When I hit the Show details button I get:cstddef:50:10: fatal error: 'stddef.h' file not found
mainwindow.cpp:1:1: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.cpp:1:
mainwindow.cpp:1:10: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.cpp:1:
mainwindow.h:4:10: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.h:4:
QMainWindow:1:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/QMainWindow:1:
qmainwindow.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qmainwindow.h:43:
qtwidgetsglobal.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qtwidgetsglobal.h:43:
qtguiglobal.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtGui/qtguiglobal.h:43:
qglobal.h:46:12: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:46:I should be copying this from a newly started program, but instead I am taking if from a newly started project in which I have added some widgets and a slot. Still, at least most of this is there before I start to modify the program.
In main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv); o variable has incomplete type ‘QApplication’
MainWindow w; o unknown type name ‘MainWindow’
w.show();
return a.exec();
}
at the top of this window in the yellow box:cstddef:50:10: fatal error: 'stddef.h' file not found
main.cpp:1:1: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/main.cpp:1:
main.cpp:1:10: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/main.cpp:1:
mainwindow.h:4:10: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.h:4:
QMainWindow:1:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/QMainWindow:1:
qmainwindow.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qmainwindow.h:43:
qtwidgetsglobal.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qtwidgetsglobal.h:43:
qtguiglobal.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtGui/qtguiglobal.h:43:
qglobal.h:46:12: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:46:and at the bottom of this window:
o variable has incomplete type: ‘QApplication’
forward declaration of ‘Qapplication’
unknown type name: ‘MainWindow’And finally in mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QmainWindow o expected class name (continues off screen, no horizontal scroll bar)
{
Q_OBJECT o incomplete result type ‘Qstring’ in function definition o calling ‘tr’ with incomplete return type ‘Qstring’ o incomplete result type ‘Qstring’ in function definition o callingAt the top in the yellow box:
cstddef:50:10: fatal error: 'stddef.h' file not found
mainwindow.h:1:1: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.h:1:
mainwindow.h:4:10: note: in file included from /home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.h:4:
QMainWindow:1:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/QMainWindow:1:
qmainwindow.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qmainwindow.h:43:
qtwidgetsglobal.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qtwidgetsglobal.h:43:
qtguiglobal.h:43:10: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtGui/qtguiglobal.h:43:
qglobal.h:46:12: note: in file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:46:and at the bottom:
there is too much to type there, and no way to copy it to paste it here. I will attach a picture of it.
If I remember correctly, I get an error when I try to add stddef.h
Please tell me how to fix these problems. Thank you.
-
@Citabria said in Issues in new project from creation:
I am using QT Creator 4.11.0, on an Ubuntu laptop.
These issues don’t prevent compilation and running of the program, but they do create many warnings and I don’t know how to fix it.What version of Ubuntu? You should always say. Assuming >= Ubuntu 20.04, you need to
sudo apt install clang-9
, clang version 9 instead of the version 8 which comes with Ubuntu 20.04. That will make your Creator Code Model correctly parse your source files. -
@JonB
I have 20.04.1
Here’s what I got when I did what was suggested:chris@chris-XPS-13-9310:~$ sudo apt install clang-9
[sudo] password for chris:
Reading package lists... Done
Building dependency tree
Reading state information... Done
clang-9 is already the newest version (1:9.0.1-12).
clang-9 set to manually installed.
The following packages were automatically installed and are no longer required:
apt-clone archdetect-deb dctrl-tools dmraid gir1.2-timezonemap-1.0
gir1.2-xkl-1.0 kpartx kpartx-boot libdebian-installer4 libdmraid1.0.0.rc16
libtimezonemap-data libtimezonemap1 python3-icu python3-pam rdate
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
chris@chris-XPS-13-9310:~$This doesn't seem to have helped. I rebooted, rebuilt, still getting all the same issues.
-
Hi, Thanks for your quick reply. I wish it had been the answer. While I am waiting for another response there were a few things I thought I should add.
First, I tried to attach the photo of the other error messages but couldn't. I did find a small symbol that said picture, but hitting it only put a URL link into my test, and I saw no way to get a file browser so I could point to the file.
Of course I saw from the feedback from the terminal that I already had the newer file. This Linux laptop is only about 2-1/2 months old. I downloaded the latest version of QT Creator only about 3-1/ weeks ago.
I am experiencing two other problems that may arise from the same cause, and so I should tell about them in case they are clues to the problem.
The first program I wrote using QT Creator works well. It uses lineEdits to display numbers, and to get user input when a new number needs to be typed in. I am using the editing finished signal to call a function in which the number is retrieved from the lineEdit, converted to a number, number put into global variable, some math done, results put into variables, variables converted to text and displayed in lineEdits. This is all working perfectly when the signal is called by changing focus, clicking into another lineEdit. But if I use the return key to send the signal, odd things happen. It puts a zero into some of the variables. It is odd and I have not tried to figure out the problem yet. It may be caused by the same cause. Or, is there something completely different about calling editing finished by changing focus, from using the return key.
I have started a new program. I am using a stacked widget. On the first page I have a bunch of buttons which are menu items, which change the page. I added most of these by coping them form the first one I added. Suddenly things have changed, even when I add a new button, and also with lineEdits. The text property had disappeared from the properties editor. I can right-click and say change text to do it. But most of the other properties have become un-editable. In fact I think all of them. Is there something I don't know about QT Ceator, or is this a problem possibly resulting from the same cause as my original reason for writing this question ? Is there a way to get the widgets properties to be editable again ? -
Also, I had edited the properties of a large number of buttons simultaneously, by selecting them all first. It worked, but perhaps it is that that caused their properties in the property editor to become un-editable.
Another thing happened. I had all the buttons set to allow line wrap. This worked well because the two words I had in the buttons at first, broke into two lines when I squeezed the form horizontally, allowing it to become smaller, allowing all the buttons to become smaller horizontally than they could without line wrap.
I then experimented with the size policy property. After changing this, I was never able to get line wrap to work again.When I first discovered that the properties had become un-editable, I thought it was because of having added layouts. But removing them didn't fix it.
-
HI @Citabria,
Do the warnings go away after you compiled your program successfully the first time?
OtherwiseI have two hints for you:
-
Upgrade Qt Creator, e.g. by installing the latest version from https://download.qt.io/official_releases/online_installers The Clang Code Model improved a lot in the latest versions (we now have 4.14.1 and a first beta of 4.15)
-
/home/chris/C++/STL QTC/Testing/TestingOne/mainwindow.cpp:1:
By all means avoid spaces and other non-ASCII characters in project paths. They will hit you sooner or later.
Best regards
-
-
Thanks for the info. I had thought I might have some sort of corrupted installation and might need to install a new version. Do I uninstall first, and then install the new, and will my project files be safe ? Of course I'd back them up first anyway.
I am not sure that all the errors were there when I first successfully compiled the first early versions of the first program. I am not sure when I first noticed them. But since I first noticed them, they have never gone away.
I have been working on a new program but I opened the first and found it also suffers from all the properties not being editable, or at least most of them. I don't think it did that before so either the program is corrupting, or I have unknowingly switched something that caused the properties to be locked.
-
Hi, I uninstalled the older version and installed the newer one from the link.
It fixed all the "issues". It fixed the problem where hitting return instead of changing focus was doing odd things.
Only one problem remains. Most of the attributes in the attribute editor are still un-editable for my widgets. What can I do to fix this ? -
Sorry, my fault. The attributes are editable. I had the editors on the sides squeezed a bit to show more of the form. So the attributes weren't visible, only the titles. Silly mistake. I think everything is working now. Thank you very much for your help.