How can completely port a qt3 library to qt4? - c++

I have been stumbling through some different steps to do this. I ran the qt3to4.exe on the files with compile errors and got though a lot of conversion steps, however now I am getting this error:
1>c:\qt\4.7.0\src\qt3support\widgets\q3toolbar.h(64) : error C2039: 'ToolBarDock' : is not a
member of 'Qt'
and 55 other similar errors. This confuses me since it is in qt's own q3support library. I also saw on a QT help page (http://doc.trolltech.com/4.2/qt-qt3.html) that ToolBarDock is deprecated and Qt::Dock should be used instead.
I haven't found much help on this out there. I'm using the library inside Visual Studio 2008. Any QT/visual studio experts out there?
If this helps, here is the code it is failing on in q3toolbar.h:
Q3ToolBar(const QString &label,
Q3MainWindow *, Qt::ToolBarDock = Qt::DockTop,
bool newLine = false, const char* name=0);

Actually qt34qt4 doesn't do all things right. There are many methods, enums etc, which are not converted. It is more or less simple find-replace tool which replace following instructions from qt\tools\porting\q3porting.xml
In many cases there is a replacement definition for a class, but not for a method of this class. In some cases qt3to4 replaces enums and methods in code which doesn't belong to Qt-classes at all. So be carefull. In any case, I would suggest getting a list of all Qt classes in you code, read carefully porting notes (http://doc.qt.nokia.com/4.5/porting4.html) for each class you use.
Another issue are return types, qt3to4 doesn't check how the returned value is used. Fortunate qt3to4 makes a good job, so fixing the rest is often a trivial, repetitive task.
If you have to port UIs, take a look at undocumented argument -wrap of uic3.
P.S.: Some figures for your effort estimation, may be usefull: I've ported (got compiled) once 600TLOCs + 150 UIs in 2,5 Months, currently I am porting about 150 TLOCs project and got pretty far in 2 weeks.

I had these errors as well after importing a project into VC++. Adding QT3_SUPPORT to the preprocessor definitions fixed it.

I ended up going a different route on this problem. I found the implementations I needed from the "qt3 library" somewhere else. Just before I found that out, I got some advice from some coworkers here. The consensus was that I'd need to rebuild Qt specifying to include qt3 support. Although I didn't follow through with this, here are some helpful links.
http://www.qtcentre.org/wiki/index.php?title=Qt4_with_Visual_Studio
http://lists.trolltech.com/qt-interest/2006-11/thread00177-0.html
If anyone comes across this and gets through this problem, please post your solution! Thanks.

Related

C++ in Netbeans: many senseless "unexpected token" hints

I am very new to coding C++ and to using the Netbeans IDE. Worse yet, I'm on a Mac (but I can't imagine that's the source of the issue this time).
The IDE is giving me countless nonsense "hints" as in red exclamation mark symbols, most of which say "Unexpected token" for things like ';' at the end of a statement or '=' in a statement. These are of course ridiculous because, as I understand c++ so far, they are necessary for even the most basic statements!
screenshot here
What could possibly be causing this and how do I get rid of the hints or, preferably, fix something if there is an error somewhere?
Delete your Netbeans cache. In my case the problem when away when I did this. I think I initially ended up in this state because my C++ project was under a Java project. After separating the two the error was still present even with a clean/build. Deleting the Netbeans cache got rid of the problem. Even if your situation is different you should try this. Clearing the Netbeans cache once in a while fixes a lot of issues.
Tyler,
I'm going to go out on a limb and guess that you've got your Net beans ide setup to use another language other than C++. Remake the project and make sure your using c++
I had the same issue.
The issue was, I wrote C++14 code, in the C++ project.
To resolve this:
- Create a C++14 project (Select from the drop down, while creating the project)
- Add existing C++ files to it
Hope that helps.

What's the deal with the CRT SECURE warnings/errors on visual studio?

I encountered this issue a dozen, if not a million times already: I compile a c++ program on visual studio and get a dozen, if not a million warnings and/or errors suggesting that I am doing something very dangerous and that there is no way my compiler will let me do that. the warnings/errors tell me that I am using a deprecated function and that I should consider using some other safer function that may or may not do the same thing as this one, but I have no idea what this one does in the first place since I did not write it.
After some research (I do it everytime, I am not a quick learner) I find out I am not the first one facing this particular problem, and I can coerce my compiler to work with this program with the proper macro definition (for the future readers who don't care about my question but want to compile their program, you have to define _CRT_SECURE_NO_DEPRECATE, don't you ever dare following visual studio's advice and using the allegedly safe function).
I have often read in the manual or on this very website, along with the answer, the fact that I should not do that if I don't know precisely what I am doing.
I must confess: I have no idea what I am doing, and I would be very grateful if someone would accept to explain it to me.
So here are my questions:
What are those functions that are unsafe? Why do they exist in the first place?
What is unsafe about them?
Why are they so often found in perfectly honourable libraries?
I have come to the understanding that there is no safe and portable alternative to those functions: why is it so? How about we have some people think about it and try to define a way to do it, and everyone would accept to do it that way, and we would call it standard maybe?
To tackle your questions in order:
They exist in the first place because the standard wrote them in such a way. Standards authors are human so don't think of everything and this left some security weaknesses in the C API. You can find a list of these deprecated functions at http://msdn.microsoft.com/en-us/library/ms235384.aspx.
Many of the functions are unsafe as they allow such things as buffer overruns to occur but other security vulnerabilities may be exposed depending on the function.
Honourable libraries generally try for some cross platform compatibility so I suspect will try to stick to stand C rather than using compiler specific functions and extensions.
The "perfect" standard will probably never exist as in my first point :) Some of the C API problems can be avoided using C++ but that's a big hammer to crack a small nut and brings security vulnerabilities of its own.

Qt, MSVC, and /Zc:wchar_t- == I want to blow up the world

So Qt is compiled with /Zc:wchar_t- on windows. What this means is that instead of wchar_t being a typedef for some internal type (__wchar_t I think) it becomes a typedef for unsigned short. The really cool thing about this is that the default for MSVC is the opposite, which of course means that the libraries you're using are likely compiled with wchar_t being a different type than Qt's wchar_t.
This doesn't become an issue of course until you try to use something like std::wstring in your code; especially when one or more libraries have functions that accept it as parameters. What effectively happens is that your code happily compiles but then fails to link because it's looking for definitions using std::wstring<unsigned short...> but they only contain definitions expecting std::wstring<__wchar_t...> (or whatever).
So I did some web searching and ran into this link: https://bugreports.qt.io/browse/QTBUG-6345
Based on the statement by Thiago Macieira, "Sorry, we will not support building Qt like this," I've been worried that fixing Qt to work like everything else might cause some problem and have been trying to avoid it. We recompiled all of our support libraries with the /Zc:wchar_t- flag and have been fairly content with that until a couple days ago when we started trying to port over (we're in the process of switching from Wx to Qt) some serialization code.
Because of how win32 works, and because Wx just wraps win32, we've been using std::wstring to represent string data with the intent of making our product as i18n ready as possible. We did some testing and Wx did not work with multibyte characters when trying to print special stuff (even not so special stuff like the degree symbol was an issue). I'm not so sure that Qt has this problem since QString isn't just a wrapper to the underlying _TCHAR type but is a Unicode monster of some sort.
At any rate, the serialization library in boost has compiled parts. We've attempted to recompile boost with /Zc:wchar_t- but so far our attempts to tell bjam to do this have gone unheeded. We're at an impasse.
From where I'm sitting I have three options:
Recompile Qt and hope it works with /Zc:wchar_t. There's some evidence around the web that others have done this but I have no way of predicting what will happen. All attempts to ask Qt people on forums and such have gone unanswered. Hell, even in that very bug report someone asks why and it just sat there for a year.
Keep fighting with bjam until it listens. Right now I've got someone under me doing that and I have more experience fighting with things to get what I want but I do have to admit to getting rather tired of it. I'm also concerned that I'll KEEP running into this issue just because Qt wants to be a c**t.
Stop using wchar_t for anything. Unfortunately my i18n experience is pretty much 0 but it seems to me that I just need to find the right to/from function in QString (it has a BUNCH) to encode the Unicode into 8-bytes and visa-versa. UTF8 functions look promising but I really want to be sure that no data will be lost if someone from someplace with a more symbolic language starts writing in their own language and the documentation in QString frightens me a little into thinking that could happen. Of course, I could always run into some library that insists I use wchar_t and then I'm back to 1 or 2 but I rather doubt that would happen.
So, what's my question...
Which of these options is my best bet? Is Qt going to eventually cause me to gouge out my own eyes because I decided to compile it with /Zc:wchar_t anyway?
What's the magic incantation to get boost to build with /Zc:wchar_t- and will THAT cause permanent mental damage?
Can I get away with just using the standard 8-bit (well, 'common' anyway) character classes and be i18n compliant/ready?
How do other Qt developers deal with this mess?
I would agree with Öö Tiib's remark
That option is perhaps for
compatibility with some old legacy
pre-wchar_t code.
Having in mind that Qt is ported to many different platforms (including embedded systems), some of them not having a decent C++ compiler, I would guess that this switch is just to make it possible to compile Qt on those platforms. I mean it's probably not something that Qt relies on to work correctly. If it were the case it would mean that Qt's design is deeply broken in my opinion. So option 1 should work.
Having said that I would definitely recommend choosing option 3 because
wchar_t gives you almost nothing in
regard to i18n
as you noticed Qt has very capable string class
which makes i18n an easy task (see
Internationalization with Qt)
You might take a look at results of searching for wchar_t on qt-interest#qt.nokia.com list, ask your question there and talk to Thiago Macieira on freenode.net #qt irc channel where Thiago is very active.
Stumbled over the same issue ...
Obviously bjam expects cxxflags=-Zcwchar_t-
After building the static serialization libs via
bjam --with-serialization toolset=msvc-8.0 variant=debug threading=multi link=static cxxflags=-Zc:wchar_t-
everything linked like expected.
Hope this helps anyone.
Putting this here as an answer because it's too long for comment.
Here's one of the answers to why one might be getting LNK2019 aka "symbol not found" linker error (source):
You mix code that uses native wchar_t with code that doesn't. C++ language conformance work that was done in Visual C++ 2005 made
wchar_t a native type by default. You must use the /Zc:wchar_t-
compiler option to generate code compatible with modules compiled by
using earlier versions of Visual C++. If not all modules have been
compiled by using the same /Zc:wchar_t settings, type references may
not resolve to compatible types. Verify that wchar_t types in all
modules are compatible, either by updating the types that are used,
or by using consistent /Zc:wchar_t settings when you compile.
So that could be the main reason why /Zc:wchar_t- is there in all cl.exe-related mkspec files and also why you probably don't need it.
I like having native wchar_t because it makes it sometimes easy to convert between the strings that the windows api expects and QString.
wchar_t should be type like bool or long. No headers are needed to define it.
You did use that "wchar_t is undefined type" option. Then you typedef wchar_t as unsigned short and then you wonder that nothing works anymore?
That option is perhaps for compatibility with some old legacy pre-wchar_t code. Just simply ... never use it. Otherwise nothing C++ links to it because functions that take wchar_t parameters are differently name-mangled than functions that take unsigned short parameters.
If some library is compiled with some strange options then build it with correct options. When needed then fix its code. If you can not do it then you should not use that library. Every line of code in your C++ project is yours to maintain.

C++ IDE for Linux with smart reference searching

Is there an IDE supporting C++ with REALLY smart searching of references? By 'reference' I mean usage of a class (or its member), variable, function in the whole Project or Workspace.
There's lots of IDE providing it. Some of them seem just to search for the text with same name giving lots of stuff, others are smarter and check the context (like class boundaries, namespace) but aren't accurate enough.
The best I've tried so far was Visual SlickEdit, but still there's more to wish.
class C1
{
int foo;
};
class C2
{
int foo;
};
For example in this situation when searching for C1::foo references I DON'T want C2::foo to be shown too.
So, is there an IDE that would be so smart?
Edit2
10x everybody for the answers so far.
I tried Eclipse, reference searching seems relatively good, but it takes it 20 minutes to index medium size project and 4 times of 5 it runs out of memory and crashes. I tried increasing it and some other advice and it got a little better, but still quite slow and annoying with these crashes.
I tried KDevelop3, but the feature mentioned in this question is not very advanced - seems to be just very advanced grep based text searching.
Edit4
KDevelop4 - I tried to make it work, but latest beta it's quite unusable for custom makefile projects, I was unable to do anything with it.
Edit5
I was surprised, but QT Creator did really well in my tests. It doesn't seem to create some tag/index files, but somehow manages to show very precisely the usage of variable/functions/classes. Unfortunately it seems to not work very correctly with templates, when following definitions of functions.
None of the mentioned IDEs could compete Visual SlickEdit in working with references, virtual functions, etc. QT Creator was the closest though, so I will choose it as an answer to my question.
I think that you could use Eclipse , mainly i think that it will be able to do what you want, or nearly enough. Also here's a brief description of it's search options.
I think Qt-Creator can help you. There few new features added in new preview 2.0.
No and I don't think we will ever see implementations that are as good as those in C# or Java editors for two reasons:
1) the preprocessor:
#ifdef _DEBUG
#define FOO(x) C1(x).foo
#else
#define FOO(x) C2(x).foo
#endif
2) templates:
template<class C> void Method(C const& c) {
printf("%d", c.foo);
}
In both cases it is hard to determine which class is actually referenced.
Did you ever try Netbeans. Close competitor of Eclipse it has all its feature like web development, mobile application ide, plugins to almost allow anything to do. All this with lower CPU and memory footprint. And it does resolve the name correctly.
I have not used KDevelop myself, but I get the impression that it does some serious parsing of the source code and is able to access source code information though the editor . It has at least some advanced code assistant functionality.
You have to try KDevelop 4, not the old one.
You can look at CodeBlocks [http://www.codeblocks.org/]. I just started using it, but not tested for your requirement. So I am not claiming 10X now. But you can give it a try. Its open source and good one.

How to setup VS2008 for efficient C++ development

Normally I program in C# but have been forced to do some work in C++. It seems that the integration with Visual Studio (2008) is really poor compared to C# but I was wondering if there are any good tools, plugins or configurations that can improve the situation.
Another post pointed out the program Visual Assist X, which at least helps with some things such as refactoring (though it is a bit expensive for me). My major problem is, though, that the compile errors give little clue about what is wrong and I spend most of my time figuring out what I did wrong. It just feels like it is possibly to statically check for a lot more errors than VS does out of the box. And why doesn't it provide the blue underlines as with C#, that shouldn't be too hard?!
I realize that half the problem is just the fact that I am new to C++ but I really feel that it can be unreasonably hard to get a program to compile. Are there any tools of this sort out there or are my demands too high?
I think there are two possibilities: 1) either you're trying out C++ stuff that is waaay over your knowledge (and consequently, you don't know what you did wrong and how to interpret error messages), 2) you have too high expectations.
A hint: many subsequent errors are caused by the first error. When I get a huge list of errors, I usually correct just the first error and recompile. You'd be amazed how much garbage (in terms of error messages) a missing delimiter or type declaration could produce :)
It is difficult to syntactically analyze a C++ program before compilation mainly for two reasons: 1) the C++ grammar is context-dependent, 2) templates are Turing-complete (think of them as of a functional programming language with a weird syntax).
My suggestions:
If you want more features like you get in C#, get VisualAssist X, and learn how to use it. It isn't free but it can save you a lot of time.
Set your warning level high (this will initially generate more compile-errors but as you fix them, you'll get a feel for common mistakes).
Set warning as error so you don't get in the habit of ignoring warnings.
To understand compile errors, use Google (don't waste your time with the help system) to search on warning error numbers (they look like this: C4127).
Avoid templates until you get your code compiling without errors using the above methods. If you don't know templates well, study! Get some books, do some tutorials and start small. Template compile errors are notoriously hard to figure out. Visual C++ 2008 has much better error messages than previous versions but it's still hard.
If you start doing templates in earnest, get a wide-screen monitor (maybe even two) to make reading the verbose errors easier.
+1 for Visual Assist, maybe not now - but when you turn the hobby into a profession you will need it.
In my experience, the diagnsotics are already much better than in VC6, but you will need to "learn" their true meaning as part of learning the IDE.
Static checking of C++ is much more complicated than C#, due to the build mode, and the incredibly more complex language. PC-Lint (best together with Visual Lint to integrate it into the IDE) is the canonical static analysis. Not cheap either, though...
The C++ standard sometimes reads like scripture, but without a trained preacher to interpret it. One excellent interpreter is Marshal Cline with his C++ FAQ. Note that the online FAQ, while extensive, covers much less than the book.
What helped me a lot understanding complex error messages is trying to reproduce the problem in a smaller environment - but then, there was no internet back then...