I am writing a C++ library and have just remembered that I need to export each class.
The following code:
class MyClass
should become:
class MY_EXPORT MyClass
I have several classes that need this change - is there a way to do this using Qt Creator?
You can achieve this using the Advanced Search feature:
Edit > Find/Replace > Advanced Find > Open Advanced Find...
or CTRL + SHIFT + F
Search Results
window that opens, select an appropriate Scope
(Current Project
is probably sufficient in your case).Check Use regular expressions
.
In the Search for
field, type:
^class (.*[^;])$
This searches for all class declarations that begin at the start of the line and don't end with a semicolon (to exclude forward declarations).
In the File pattern
field, type:
*.h
This will ensure the search only happens within header files.
Click the Search & Replace
button. You'll be presented with a list of search results, and the message "This change cannot be undone." - now would be a good time to commit your work if you haven't already.
Expand each search result to check that the matches are correct. Once you're satisfied, type the following into the Replace with
field:
class MY_EXPORT \1
This adds MY_EXPORT
before the name of each class, using a numbered backreference to insert the class name captured with the group back in step 4.
Click the Replace
button, and you're done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With