問題描述
所以 Qt 在 windows 上是用/Zc:wchar_t- 編譯的.這意味著 wchar_t 不是某些內部類型(我認為是 __wchar_t)的 typedef,而是 unsigned short
的 typedef.真正酷的是 MSVC 的默認值是相反的,這當然意味著您使用的庫很可能是用 wchar_t
編譯的,而 wchar_t
與 Qt 的 wchar_t代碼>.
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
.
這當然不會成為問題,除非您嘗試在代碼中使用諸如 std::wstring
之類的東西;特別是當一個或多個庫具有接受它作為參數的函數時.實際發(fā)生的情況是,您的代碼可以愉快地編譯但隨后無法鏈接,因為它正在使用 std::wstring<unsigned short...>
查找定義,但它們只包含需要 std 的定義::wstring<__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).
所以我做了一些網絡搜索并找到了這個鏈接:https://bugreports.qt.io/browse/QTBUG-6345
So I did some web searching and ran into this link: https://bugreports.qt.io/browse/QTBUG-6345
根據 Thiago Macieira 的聲明,對不起,我們不會支持這樣構建 Qt",我一直擔心修復 Qt 使其像其他任何東西一樣工作可能會導致一些問題,并一直試圖避免它.我們使用/Zc:wchar_t- 標志重新編譯了我們所有的支持庫,直到幾天前我們開始嘗試移植(我們正在從 Wx 切換到 Qt)一些序列化時,我們對此感到相當滿意代碼.
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.
由于 win32 的工作方式,并且因為 Wx 只是包裝了 win32,我們一直使用 std::wstring
來表示字符串數據,目的是使我們的產品盡可能為 i18n 做好準備.我們做了一些測試,當嘗試打印特殊的東西時,Wx 不能處理多字節(jié)字符(即使不是像度數符號這樣特殊的東西也是一個問題).我不太確定 Qt 是否存在這個問題,因為 QString 不僅僅是底層 _TCHAR 類型的包裝器,而且還是某種 Unicode 怪物.
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.
無論如何,boost中的序列化庫已經編譯了部分.我們已經嘗試使用/Zc:wchar_t- 重新編譯 boost,但到目前為止,我們試圖告訴 bjam 這樣做的嘗試都沒有受到重視.我們陷入了僵局.
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:
重新編譯 Qt 并希望它適用于/Zc:wchar_t.網絡上有一些證據表明其他人已經這樣做了,但我無法預測會發(fā)生什么.所有在論壇上詢問 Qt 人員的嘗試都沒有得到答復.見鬼,即使在那個錯誤報告中,也有人問為什么,它就在那里呆了一年.
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.
繼續(xù)與 bjam 戰(zhàn)斗,直到它聽到為止.現在我已經有人在我手下這樣做了,而且我有更多的經驗與事物作斗爭以獲得我想要的東西,但我不得不承認我已經相當厭倦了.我也擔心我會繼續(xù)遇到這個問題,因為 Qt 想成為一個 c**t.
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.
停止使用 wchar_t 做任何事情.不幸的是,我的 i18n 體驗幾乎為 0,但在我看來,我只需要在 QString(它有一個 BUNCH)中找到正確的 to/from 函數即可將 Unicode 編碼為 8 字節(jié),反之亦然.UTF8 函數看起來很有希望,但我真的想確保如果來自某個地方的人使用更符號化的語言開始用他們自己的語言編寫并且 QString 中的文檔讓我有點害怕認為可能發(fā)生的情況,則不會丟失任何數據.當然,我總是會遇到一些堅持使用 wchar_t 的庫,然后我又回到了 1 或 2,但我很懷疑這會發(fā)生.
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...
這些選項中哪個是我最好的選擇?Qt 最終會不會因為我決定用/Zc:wchar_t 編譯它而導致我挖出自己的眼睛?
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?
使用/Zc:wchar_t- 增強建造的魔法咒語是什么,這會造成永久性的精神傷害嗎?
What's the magic incantation to get boost to build with /Zc:wchar_t- and will THAT cause permanent mental damage?
我可以只使用標準的 8 位(好吧,無論如何都是通用")字符類并符合 i18n 標準/準備好了嗎?
Can I get away with just using the standard 8-bit (well, 'common' anyway) character classes and be i18n compliant/ready?
其他 Qt 開發(fā)人員如何處理這個爛攤子?
How do other Qt developers deal with this mess?
推薦答案
偶然發(fā)現了同樣的問題...顯然 bjam 期望 cxxflags=-Zcwchar_t-
Stumbled over the same issue ...
Obviously bjam expects cxxflags=-Zcwchar_t-
通過
bjam --with-serialization toolset=msvc-8.0 variant=debug threading=multi link=static cxxflags=-Zc:wchar_t-
一切都像預期的一樣.
希望對大家有所幫助.
這篇關于Qt、MSVC 和/Zc:wchar_t- == 我想炸毀世界的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!