QCreator designer widget inaccessible from program code - c++

Preface: I am using Qt Creator 2.4.1 (based on Qt 4.7.4, 64-bit) on Mac OS X Lion installed via the Qt SDK.
I am working on a project where I have a UI created using the designer in QCreator. I have several widgets working without issue. I created a new QPushButton widget by dragging it from the desiger palette and set some properties in the designer. However, I am unable to access it from the source code using the ui->[widget] convention. I can access every other widget on the form as expected. A search of the site yielded one similar issue, however the solution specified does not work for me.
I've tried:
Clean, full rebuild
Re-running qmake
Restarting QCreator
I have checked the ui element's generated XML and the widget is included and with the correct objectName and properties, yet the source code portion of the designer does not see it.

I solved this issue by deleting the current working directory, checking out the latest source from version control, and creating a new project. After further scrutiny, I found that ui_mainwindow.h, which is generated every compile by qmake, had been moved into the source directory instead of the build directory, which must have caused some internal conflict with QCreator where it would not regenerate it and just copy the old one to the build folder. Deleting the file probably would have worked if I had seen it and saved me the time of starting fresh.

Related

UI not getting upated inside QT designer

Recently I started learning QT framework for developing GUI applications* in C++. Till now everything was fine with QT creator but when I try to change the background color of an element using CSS style sheet the QT UI designer does not get updated. Moreover even while writing the code the QT doesn't detect my newly added controls to the screen. Here is a GIF to show this problem.
Also I am not sure if that's the way QT works but after adding an element on the form I am not able to access that element by its object name in code immediately unless I build it again
Here is my QT details
Forgive me if i went wrong somewhere or made any mistakes, I am a Visual Studio guy and am quite new with using QT.
Note: I am asking that second one because i have seen a lot of tutorial videos on QT widget where the object could be accessed immediately in code after adding it.
Also first time when I used it, it did work. But since then the designer doesn't get updated
It was pretty much easy. I just had to change the border property to any value and immediately changes can be seen. It was because of the border i guess that was causing the problem.
Here is a gif to show you that...
And regarding the issue of mainwindow.ui not matching with ui_mainwindow.h file the solution was pretty simple both the build directory and working directory contain the same file called ui_mainwindow.h Delete the one in the working directory and bingo it works.
Thanks to this QT forum's post
[Solved] What would cause a mainwindow.ui file not to match with it ui_mainwindow.h file?
Note: Whenever the project is built or run, the ui_*.h files will be generated again causing you to delete the files again and again. A solution for that is to add a makefile in the working directory that automatically deletes the ui_*.h files after building the project ( post build step ). Here are the steps for it.
Step 1 : Create a makefile called deleteUI_header.mk and add the following code to it as shown in the figure below
Step 2 : Save the file in the working directory of the project.
Step 3 : Now open the project in QT and click on the project tab in the left hand side. Under build settings->build step click on add build step->make
Now override jom.exe with make (ensure that make's location is present in PATH environment variable ) and provide the following make argument
-f deleteUI_header.mk
Now whenever you will build the project the ui header files generated will automatically be deleted.
`

Use a QT Widget plugin using static qmake

i have built an QT GUI app using Visual Studio 2017 with Qt VS Tools extension and QT version 5.6 (the one provided by QT precompiled), using Qled widget plugin.
With this Default Dynamic Qt version, the app runs fine with the widget and i have no problems.
But now, i want to build the same app, but static, for use without dependencies.
So, i built QT 5.6 from source with -static parameter, to be more exact i follow this blog's guide. Here problems started to show up:
I tried to rebuild the widget plugin using the static qmake, but i got this error: "Project ERROR: Unknown module(s) in QT: designer"
I tried to use the plugin compiled by the dynamic qmake, and surprisingly, it built with success but the GUI app didn't open at all.
Its worth mentioning that i can use and build a simple default application using a qmake static build.
I think i need to add the Qt Designer Module, but i don't know how to do this, i even tried to rebuild qmake without the "-nomake tools" paramter, but got the same error building the plugin.
just don't build the plugin, you don't need it. Just add the qrc file, and the actual widget *.cpp and *.h file into your project
fix the linkage, delete the QDESIGNER_WIDGET_EXPORT in the *.h file inside your project
This comment managed to solved my problem, thanks to #PeterT

Qt Charts and Data Visualization widgets

I have installed Qt 5.7 in order to try Qt Charts and Qt Data Visualization but I cannot find new widgets neither in Qt Designer nor in Qt Creator. Any suggestions what should I do so new widgets appear in designer?
I was having exactly the same problem today. It looks like the QT Designer plugins of QT Charts are not part of the package by default. I ended up downloading the designer plugin sources from github https://github.com/qtproject/qtcharts/tree/5.7/plugins/designer
This consists of just 5 files.
You should then be able to open the designer.pro project in Qt Creator and compile it. Place the resulting library in your designer plugin directory. This will make the QChartsView widget appear in the Qt Designer.
Just elaborating on Holger's answer for ubuntu, compile, in terminal using qmake and make (doesn't work in qt creator - you need qt chart development package installed, which I believe is not available at this point in time), the designer.pro file in /opt/Qt/5.7/Src/qtcharts/plugins/designer directory then, copy and paste the shared library into /opt/Qt/Tools/QtCreator/lib/Qt/plugins/designer directory, where /opt/Qt is the directory in which Qt is installed.
I would like to add this as a comment to the accepted post:
If you are using python to build your project and process the .ui files with pyuic5 it might be the case that pyuic5 leaves you with an error message stating that QtChart.QChartview could not be found. This is the workaround:
Go to the site-packages/PyQt5/uic/widget-plugins directory, it should look something like this:
/widget-plugins/
__pycache__/
qaxcontainer.py
qscintilla.py
qtcharts.py <- create this file by copying qtquickwidgets.py and renaming
qtprintsupport.py
qtquickwidgets.py
qtwebkit.py
qtcharts.py looks like this (you have to edit the file):
# copyright information
pluginType = MODULE
def moduleInformation():
return "PyQt5.QtChart", ("QChartView", )
I also encountered this problem today, but Holger's way didn't work on my situation. After consulting other people via internet, I finally fixed it. And my solution is quiet simple, I just open the Maintenance Tool and choose add components, select Qt Charts and Qt Data Visualization, and click next, and then it works. This problem happens because by default Qt Charts is not selected while installing Qt, so we should add this component manually.
But I also should mention that maybe this way just work on Qt which was installed by Qt Online Installer, and if you installed Qt via offline Installer, maybe you should reinstall it.

Qt Ui Existing But Ui Header and Source Not Existing

I have received a demo Qt project for a product.
I am trying to build the project and run it.
I am getting such a kind of error in Qt Designer when I try to build the project.
It says ui_FOO.h does not exist.
I see that FOO.ui (the qt designer form exists) but source and header files for it do not exist. And thats why i am getting the error.
What should I do to be able to build and run my project?
Add the following line to the pro file to get uic generate the C++ header from the ui file:
FORMS = FOO.ui
and build your project again.
You can find more information from Using a Designer UI File in Your Application.
Oh I got it.
This is a qt4 project as it is written in manual.
I went under tools->options->build&run->qtversions and added qmake-qt4
Then under the kit manually added a kit which uses the qtversion that i just specified.
Then under projects tile clicked on add kit and the kit appeared.
I removed the qt5 kit.
Now those ui_foo.h file is generated in its corresponding build path.

Qt Designer doesn't load my custom widget plugin

I'm reading the book "C++ GUI Programming with Qt4", and I've reached the topic of Integrating Custom Widgets with Qt Designer.
I've built the example project outlined there (the icon editor plugin), and I get a file called 'libiconeditorplugin.so', and I've copied it to '/usr/lib/qt4/plugins/designer/'. But when I start Qt Creator I don't see the icon editor widget in the widget box.
The only thing I've done differently from the book is I removed the DESTDIR from the .pro file because it had $QTDIR, and $QTDIR is not defined in my computer and I don't know where it should point. Instead, I copied the .so file manually.
I'm not sure if I've copied the plugin in the right directory, and if libiconeditorplugin.so is the only file that I needed to copy, the book was kind of sketchy on how it should work.
My OS is Ubuntu and I've installed Qt Creator with apt-get.
Turns out I was copying libiconeditorplugin.so to the wrong directory. I was copying it to "/usr/lib/qt4/plugins/designer/", while Qt Designer was looking in "/usr/lib/x86_64-linux-gnu/qt4/plugins/designer/".