How can files and classes be renamed in Qt Creator? - qt

How do I rename files and classes (declaration, implementation and uses) in Qt Creator 2.0?
I can't find such feature in there.

There is no such feature in Qt Creator :(
This is what you can do:
To rename files:
close your project
rename files in Windows Explorer or some other tool
open project
update *.pro file, list *.h files in headers, *.CPP files in sources, *.ui files in forms
update all *.ccp files in the #include section to include proper files
To change class names you can use the Ctrl + Shift + R feature that changes class names in header files and source files.

If you also want to rename a form and along with its class, you have to edit your name.ui file and change the widget name and class to the new corresponding value.
You also need to rename some things in your name.h file.
namespace Ui {
class NewValueHere;
}
private:
Ui::NewValueHere* mUI;
In your name.cpp file you also have to adjust the call of creating your mUI.
mUI(new Ui::NewValueHere)

Personnally I needed to do something more.
I renamed my class "Form" to "MainWindow", and I had to go in the directory "build-yourproject...-Debug\ui_mainwindow.h" and replace every "Form" with "MainWindow" (Ctrl+f) and then it worked.
EDIT: This was a manual solution that changes a file that is re-loaded at every build, so this change is automatically lost. The right solution is to go in Qt Creator and in the upper-right corner, under the name "Object", you should have the name of your class, that is what you need to change.

Related

No headers or source files in QT creator

I'm having a problem with creating new header and source files in QT. I can only add new files to the build, it's grayed for the "main" project as you can see below.
I can create them specifically for the build and they only appear once in the documents area. There is no header tree branch. After I close qt I have to create new ones. I want them to appear in the tree and be connected with the main project. I have "hide source and headers files" option off.
I've obviously tried creating them the way it was shown on the yt. I've searched through settings but didn't found anything I could use.
You will have to add the files manually in CMake.
Go to File>New File and select what type of file you want. Typically it will be a source, header, or both (class).
Edit the CMakeLists.txt file:
qt_add_executable(myapp
myapp.qrc
main.cpp
new_file.cpp
new_file.h
)
Resources like .qml files and things like images (*.png *.jpg) are added in the myapp.qrc file

Making a qmldir File

this might seem like the dumbest question ever, but how do you make a qmldir file with Qt Creator? I need to make one so I can use a singleton for my project.
Right click in the project pane, the project folder or qrc, depending on your deployment type, Add New, General, Empty File, name it qmldir and you are set.
Keep in mind you can also register QML singletons in C++. I prefer this solution wherever possible, as it allows to give the singletons identifiers.

Qt Image from resource file

I'm trying to insert an image to my program via resource file, which is like:
<RCC>
<qresource prefix="/">
<file>green.png</file>
<file>other files</file>
</qresource>
</RCC>
and when I'm trying to load it using QImage or QPixmap, like:
QImage *green = new QImage(":/green.png");
if(green->isNull()) qDebug("null");
I always see that null message, indicating that I'm doing something wrong. One solution may be using absolute path like
"C:\\Users\\user\\Documents\\project\\green.png",
which works of course, but I'd prefer implement it using resource file. Could you please give me some advice?
All this will work if your png files are located in the same folder as .pro, .qrc, and .cpp files of your project.
Usually it is convenient to put all images to special subfolder Resources, for example. Then in .qrc the line will look like:
<file>Resources/green.png</file>
And in .cpp file:
QImage *green = new QImage(":/Resources/green.png");
First of all, you need to create a .qrc file and add image folder to it
(image folder must be contained inside of the project folder)
Right-click on the project file
Add New
Qt
Qt Resource File press Choose and do other steps
after opening .qrc file you must press Add > Add Prefix > change prefix name if you want
again Add > Add File > and choose your images
then go to mainwindow.cpp (in my project ) file and call the images as below code
in my case the icon folder is Playericons
ui->play->setIcon(QIcon(":/Playericons/icons8-pause-30.png"));
Did you remember to run qmake after adding the resource file?

How to specify Code Style settings in a Qt Creator `.pro.shared` file?

I can see from the documentation on https://qt-project.org/doc/qtcreator-2.6/creator-sharing-project-settings.html how to create a .pro.shared file that standardizes Editor settings.
But: is it possible to standardize Qt Creator's "Code Style" settings in a .pro.shared file, and if so, what is the syntax?
There is currently no UI way of doing that, not sure if we will add one at some point.
So you will need to do this manually: Set it up for a user, close the project to make sure the .user file is saved and copy copy the file into a .shared file. Remove everything you do not want to share (keep ProjectExplorer.Project.Updater.FileVersion!), while keeping the XML structure intact. You are a developer, I am sure you will manage:-)
Oh, make sure to use the oldest Qt Creator you want to support (IIRC this was introduced in 2.5, so going older than that won't help) to create the template. Creator will upgrade settings while reading them but it can not downgrade, so .shared files that are too new are going to be ignored.

Force compile-time linking of all classes in a SWC

Using Flash CS4, I am making a game that has a dozen or so sounds and a couple of music tracks. To cut down on publish/compile time, I have moved the sounds and music into an (external) SWC, which is located in a "Library Path" for the project. This works, but with a caveat...
Until before I externalised the assets, I had been dynamically instantiating the Sound objects of the embedded sound by getting their classes with getDefinitionByName.
// something like...
var soundSubClass:Class = Class(getDefinitionByName(soundClassName));
var mySound:Sound = new soundSubClass();
But now that they're located in an external SWC, I need to have "concrete" references to the classes in order to load them like this, otherwise they are not included in the published SWF, and there is a runtime error when getDefinitionByName tries to get a class that doesn't exist.
So, my question: in Flash Professional CS4, is there any way to force a library's assets to be included, regardless of whether they are statically linked?
FlashDevelop has a compiler option "SWC Include Libraries", which is exactly what I want, and is distinct from the "SWC Libraries" option. The description of the "SWC Include Libraries" option is "Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."
(Also, it's important to me that all the assets are contained within the one compiled SWF. Linking at runtime isn't what I'm after.)
Unfortunately, I don't think so. I hope this is fixed in CS5, but I wouldn't bet on it...
The current (aggravating) standard is to have a manifest class in your SWC that references all the root classes in the rest of the library:
public class MyLibManifest {
public static function manifest():void {
var class1:Class = Class1;
var class2:Class = Class2;
// etc...
}
}
Then, somewhere in your main .fla...
import com.mylibrary.MyLibManifest;
...
var myLibrary:Class = MyLibManifest;
There's no way to pull in and embed every class in an SWC by default in Flash CS4/CS5, but you may be able to do this with:
FlashDevelop
As you already know, this program's project properties has compiler options that differentiate between:
SWC Libraries: "Links SWC files to the resultin gapplication SWF file. The compiler only links in those classes for the SWC file that are required."
SWC Include Libraries: "Links ALL classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."
That second option "SWC Include Libraries" could be useful, because if you simply compile your FLA as-is into a SWC, then put that SWC and your other SWC into FlashDevelop as SWC Include Libraries, it should compile/merge them into a single SWF that will work like you want.
FlashDevelop could also simply help you build a hard-coded list of Classes in an SWC, because if you link in the SWC as a SWC Library, it will show up in the project explorer, and you can see a list of all the classes in the SWC. You can also right click each class and choose "Insert Into Document", and it will insert the full class name. If you do that, then press semi-colon enter, you will have your first class reference. Keep your mouse over the class list in the project settings and repeat this for every class in the list. It only takes a few minutes to do this for hundreds of classes, which makes creating such a list easier. It would be even faster if the thing would let you insert more than one at once, but it doesn't seem to.
Your only other option, which you said you weren't interested in for no given reason, is Runtime Shared Libraries (RSLs). It's really not that big a deal to load the file in separately, but only if you properly handle the load process and any errors that might occur. It will add some complexity to your project, and may require some extra thought, but I'd seriously consider it as an option. See the "Application Domain Inheritance" section at www.senocular.com/flash/tutorials/contentdomains/?page=2 for more information.
I am probably missing something but isn't it a case of using -include-libraries rather than library-path option of the compiler, this is what the adobe doc says about the option
Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used.
Contrast this option with the library-path option that includes only those classes that are referenced at compile time.
Adobe Documentation
I am new to all this so be gentle when you shoot me down in flames :)
You can supply the path of your assets.swc file, in ActionScript Properties, and that should work and load assets at runtime.
in flex, and whenever you have access to compiler options, you can use: -include YourClass to force the linking of the class from swc even if its not referenced from the main swf.
but i dont know if you can change compiler options from flash cs4...

Resources