UI not getting upated inside QT designer - c++

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.
`

Related

No such file “setup.h” Codeblocks wxWidgets

I have installed WxWidgets 3.0.4 but when I try to build the blank template included from wxWidgets it says ‘no such file setup.h’ and the points out a line where setup.h was included from the directory wx/setup.h
I'm assuming you're using windows. If not ignore the rest of this answer. I'm also assuming you've already built the wxWidgets libraries. If not you need to do that first.
This error almost always means 1 of 2 things. The most likely cause is that you didn't give the codeblocks wizard the correct location for the root folder of the wxWidgets distribution. The best way to do this is as follows:
From the codeblocks menu, select Settings->Global variables...
This will pop up a dialog that looks like this:
Hit the new button and enter "wx" for the name of the new variable.
Hit the "..." next the "base" item and then select the root folder for your wxWidgets distribution (the folder containing build, include, lib, etc).
Now try to create a new wxWidgets project and on the 6th page of the wizard enter "$(#wx)" for the location. Like so:
Now if you complete the wizard, you should be able to build and run the project.
If the project still won't build, the you probably have the second problem I mentioned above which is that some of the other settings you entered in the wizard don't match the settings you built the wxWidgets library with. I've described how to fix this here.

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.

QCreator designer widget inaccessible from program code

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.

Qt on Mac: add an existing UI file without rebuilding the whole project

I have a Qt project in XCode on Mac. I want to add an existing .UI file to it. When I do that by listing in the .pri file, the XCode project itself is rebuilt by qmake, and all my post-qmake settings are lost. Is there a way to insert a UI file without listing in the .pri? It's doable in a very straightforward way on Visual Studio...
There are two custom steps in the target - both call make over files in the project bundle (xcodeproj). The first one invokes qmake. The second invokes the Qt proprocessors - uic, moc. So the answer is - comment out or delete the first step, modify the makefile of the second one by hand. Add generated files (once they're generated at least once) to the project as necessary.

Qt Creator problem. UI changes not showing when project is built

I'm making changes to a form in Creator but when I build the changes are not being "refreshed".
I've gone so far as to remove every element from the form and get rid of every stylesheet but when I build the project I get the same result; as if I had never made a change at all.
What gives? Am I missing something obvious? (obvious to everyone but me.. obviously)
I guess you're using QtCreator 2.0? I found the same strange issue. You have two options:
Remove the ui_{the_name_of_design}.h from the project's build dir. Then run qmake again.
make clean or Build → Rebuild All
But the second option even doesn't help with me. By the way that's why is good to use a different build dir than that where the sources are. If some changes don't appear to be applied, just delete the content of build dir, and everything goes fine as well.
Cheers
Most likely cause if that your make procedure is not noticing the changes in the .ui file, and so it is not calling the uic tool. Try to do a make clean to see if it helps, and check your build log to see if uic is being called.
For me, the solution was to change the BuildDirectory to the same directory where the code is, instead of the **-build-desktop directory.
I stumbled upon this issue as well and one thing I noticed was that my program was still running in the background without me knowing. Ending the task through task manager fixes it and you can make changes again.
A few suggestions:
Perform a make distclean.
Use a shadow build directory. Building “inside” the source code is not advised.
Check your computer’s clock and the date and time of your files.
This thread is a little dated but since I got caught up in the same problem I thought I would share how I resolved this.
I've been incrementally building up a ui with designer under QtCreator 2.4.1/Qt 4.8.1 using a poor man's source control approach: snapshots. At one point I inadvertently created a non-shadowed build project. In a subsequent snapshot I reverted the project back to shadow build and at that point new widgets added in the ui form were no longer being recognized in the build.
Solution:
Delete stale ui_.h files from the source directory.
Delete make and ui_.h files from your shadaow build directory.
Rebuild
Latest generated ui_.h files will reappear in the shadow build directory.
No copies of ui_.h files appear in the source directory indicating that the stale files were taking precedence in the build order. Not obvious.
I have this problem and i solve it by changing the project path. I had stored the project in my flash memory when i had this problem, then i copy the project folder and it's build folder also in the Desktop and open it with QtCreator and the problem was solved.
Problem is indeed stale generated files in project source directory. This can happen both with genrated ui_*.h files, as well as with moc_*.* files. Below is not covered by existing answers, so here we go:
To remove generated files from the project source directory, without affecting Qt Creator settings or current shadow build directories, there are two principal ways, which can also be combined for extra coverage.
Go to Qt command prompt, go to project source directory and run these commands:
qmake -r
make clean
make distclean
1st one will recursively create makefiles. 2nd one will remove all files produced by building the project. 3rd one will remove the makefiles again. Then continue using shadow build from Qt Creator as before.
The problem with this is, it will leave files which are not part of the project. So if some files have been removed from project, related generated files may remain, and cause trouble if files with same name are added back. So even after this it is good idea to verify no ui_* or moc_* files remain, if you know you have removed files from project.
Use your version control software to first commit or stash/shelve all uncommitted changes, and then remove all unversioned (also otherwise ignored) files. For some version control software this may not be easy as git clean -dxf (beware, that will also lose uncommited changes and Qt Creator's custom project settings), and in that case it may be easier to just remove project source directory and get a clean checkout.
The problem with this is, if some generated files have accidentally been added to project, they will not be cleaned up with this. So it may still be a good idea to do the step 1 above too.
Above steps should be in sync so that after step 1, any files in source directory (except Qt Creators's projectname.pro.user and possible *~ backup files) should be under in version control.