📄 commonproblems.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - Common Problems</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><p><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align="center"> Common Problems</h1><br clear="all"><h2>Link error, complaining about a lack of <code>vtbl,</code> <code>_vtbl,</code> <code>__vtbl</code> or similar </h2><p>This indicates that you include the Q_OBJECT macro in a class declarationand probably also run the moc, but forget to link the moc-generated objectcode into your executable. Read <a href="moc.html">Using the Meta ObjectCompiler</a> for details on how to use moc.<p><h2>Using different versions of Qt on the same machine</h2><p>Qt programs need the following components of the Qt distribution: <dl><p><dt><b>Header files - Compile time</b><p><dd>Programmers need to include the Qt header files. Those with acommand-line compiler will typically use options such as <code>/I%QTDIR%\include</code> or <code>-I${QTDIR}/include.</code> They will need the headerfiles of the version of Qt they wish to build programs with. Theheader files are in the <code>include</code> subdirectory of Qt distributions.<p><dt><b>Meta Object Compiler - Compile time</b><p><dd>Programmers need to run the Meta Object Compiler - <em>moc.</em> The moc isfound in the <code>bin</code> subdirectory of Qt distributions.<p><dt><b>Static or shared libraries - Link time</b><p><dd>Programmers need to link with static or shared libraries. Those with acommand-line compiler will typically use options such as <code>/L%QTDIR%\lib\qt.lib</code> or <code>-L${QTDIR}/lib</code> <code>-lqt.</code> They will need thelibraries of the version of Qt they wish to build programs with. Thelibraries are in the <code>lib</code> subdirectory of Qt distributions.<p><dt><b>Shared libraries - Run time</b><p><dd>Users of programs built with the shared Qt libraries need these sameshared libraries to run the programs. The libraries are in the <code>lib</code>subdirectory of Qt distributions. Shared libraries are made availableto programs in places such as <code>C:\windows\system</code> on Windowsplatforms, directories listed in file <code>/etc/ld.so.conf</code> on Linux,standard <code>lib</code> directories on Unix, or the directories listed in theenvironment variable <code>${LD_LIBRARY_PATH}</code> on Unix/Linux.<p></dl><p>Binary packages usually consist of two parts:<p><ul><li>run time libraries in the run time package, usually called<code>qt2.</code><li>header files, the moc and static libraries in the developers' kit,usually called <code>qt2-dev.</code><p></ul><p>Depending on how you are using Qt, you need to make specific parts ofthe Qt distribution available to your programs. Typical situations aredescribed below.<dl><p><dt><b>Developers building for a single version of Qt on Unix- Qt packages</b><p><dd>You build programs with a single version of Qt, but you still needto run programs linked with another version of Qt. You are typicallya Linux developer who builds programs for Qt 2.x on a KDE desktop basedon Qt 1.4x. Qt packages are usually split into a shared librarypackage with a name like <code>qt</code> and a developer package with a namelike <code>qt-dev.</code> You will need the appropriate packages:<p><ul><li>To build programs you will need the header files, the moc and thelibraries of Qt 2.x. They are included in the developer package ofQt 2.x (<code>qt2-dev</code> or the like).<li>To run programs you will need the shared libraries of Qt 2.xand Qt 1.4x. They are included in the regular packagesof Qt 2.x (<code>qt2</code> or the like) and Qt 1.4x (<code>qt1</code>or the like).<p></ul>Just install those 3 packages. You may need to set theenvironment variable <code>QTDIR.</code><p><dt><b>Developers building for two versions of Qt on Unix- Qt sources</b><p><dd>You build and run programs for Qt v1.4x and Qt 2.x. You will need:<ul><li>the <em>header</em> <em>files,</em> the <em>moc</em> and the <em>libraries</em> of Qt 2.xand Qt 1.4x to build programs,<li>the shared libraries of Qt 2.x and Qt 1.4x to run programs (if youuse shared linking).<p></ul><p>Get source distributions of both Qt 1.4x and Qt 2.x. <ol><li>Install and build Qt 1.4x and Qt 2.x, usually in <code>/opt</code> or<code>/usr/local.</code> In the case of <code>/opt:</code><p><pre>$ cd /opt$ gunzip -c qt-1.44.tar.gz | tar xf -$ cd qt-1.44$ setenv QTDIR /opt/qt-1.44$ configure [options]$ make$ cd /opt$ gunzip -c qt-2.1.0.tar.gz | tar xf -$ cd qt-2.1.0$ setenv QTDIR /opt/qt-2.1.0$ configure [options]$ make</pre><li>Make shared libraries available to programs at run time. Eitheradd both <code>/opt/qt-1.44</code> and <code>/opt/qt-2.0.1</code> to your environmentvariable <code>LD_LIBRARY_PATH</code> or make links to the libraries in astandard directory like <code>/usr/local/lib:</code><p><pre>cd /usr/local/libln -s /opt/qt-1.44/lib/libqt.so.1 .ln -s /opt/qt-2.1.0/lib/libqt.so.2 .</pre><p></ol><p>To develop with Qt 1.4x use:<p><pre>setenv QTDIR /opt/qt-1.44setenv PATH ${QTDIR}/bin:${PATH}</pre><p>To develop with Qt 2.x use:<p><pre>setenv QTDIR /opt/qt-2.1.0setenv PATH ${QTDIR}/bin:${PATH}</pre><p>Setting the <code>PATH</code> ensures that the proper version of moc is beingused. Your <code>Makefile</code> should refer to <code>${QTDIR}/include</code> and <code>${QTDIR}/lib</code> to include the proper header files and link with theproper libraries.<p></dl><p><h2>Using Qt on X11 without a window manager</h2><p>When using Qt without a window manager on Unix/X11, you will verylikely experience focus problems. Without a window manager, there isno focus handling on X11, and no concept of an active windoweither. If you want your application to work in such an environment,you have to explicitly mark a window as active <em>after</em> showing it:<p><pre> yourWindow->show(); yourWindow->setActiveWindow();</pre><p>Note that setActiveWindow() won't work if the widget does not becomephysically visible during this event cycle. However, without a windowmanager running, this is guaranteed to happen. For the curious reader:setActiveWindow() emulates a window manager by explicitly setting theX Input Focus to a widget's toplevel window.<p><h2>Other common problems</h2><p>Other common problems are covered by the online<a href="http://www.trolltech.com/faq/tech.html">Technical FAQ</a>.<p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -