Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easy way to make that is modifing moc preprocessor. </p> <ol> <li>Go to Qt source code to <strong>qtbase/src/tools/moc</strong> e.g. (C:\Qt\Qt5.0.1\5.0.1\Src\qtbase\src\tools\moc)</li> <li>Create a new copy of moc project e.g. moc_modified</li> <li>Open the copy of moc project with QtCreator (moc.pro file)</li> <li>Open preprocessor.cpp file and go to <strong>Symbols Preprocessor::preprocessed(const QByteArray &amp;filename, QIODevice *file)</strong> function</li> <li><p>Search the line:</p> <pre><code>// phase 1: get rid of backslash-newlines input = cleaned(input); // &lt;- insert your code to modify input variable // input is a QByteArray object that contents the source code of .h file than moc is processing // I had created the replaceCustomMacros function, see next line replaceCustomMacros(input); ... </code></pre></li> <li><p>Compile the new source code. The moc executable file is generated to /bin folder (if you use windows look at c:/bin/moc.exe)</p></li> <li><p>Go to Qt bin (C:\Qt\Qt5.0.1\5.0.1\msvc2010\bin) folder and rename moc executable file e.g. moc.exe.bak</p></li> <li><p>Copy new moc executable file to Qt bin folder.</p></li> <li><p>In your current app you need to create a Macro for example:</p> <pre><code>#ifndef Q_MOC_RUN #define DB_FIELD( PROPERTY, COLUMN ) #endif //or in my case #ifndef Q_MOC_RUN #define Q_SERVICE_INFO(method, path, type) #endif </code></pre></li> </ol> <p>Finally I let you my own source code of function replaceCustomMacros:</p> <p>This function convert <strong>Q_SERVICE_INFO(method, path, type)</strong> macro to <strong>Q_CLASSINFO("srv://method", "type:path")</strong></p> <pre><code>void Preprocessor::replaceCustomMacros(QByteArray &amp;source) { QString str(QLatin1String(source.data())); QString param_exp(QLatin1String("([^,\n]+)")); QByteArray expression("Q_SERVICE_INFO\\s*\\("); expression .append(param_exp.toLatin1()) .append(",") .append(param_exp.toLatin1()) .append("(,") .append(param_exp.toLatin1()) .append(")?\\)"); QRegExp *reg_ex = new QRegExp(QLatin1String(expression)); int pos = -1, offset = -1, len = str.length(); while ((offset = reg_ex-&gt;lastIndexIn(str, pos)) != -1) { reg_ex-&gt;cap(1); pos = -(len - offset) - 1; QString capturedString = reg_ex-&gt;capturedTexts().at(0); QString pattern = capturedString; pattern.remove(0, pattern.indexOf(QLatin1String("(")) + 1); pattern.remove(pattern.length() - 1, 1); QStringList params = pattern.split(QLatin1String(",")); QString method = params.at(0).trimmed(); method = method.mid(1, method.length() - 2); QString type; if (params.length() &lt; 3) { type.append(QLatin1String("GET")); } else { type = params.at(2).trimmed(); type = type.mid(1, type.length() - 2); } QString path = params.at(1).trimmed(); path = path.mid(1, path.length() - 2); source.replace(offset, capturedString.length(), QString(QLatin1String("Q_CLASSINFO(\"srv://%1\",\"%2:%3\")")).arg(method, type, path).toLatin1()); } delete reg_ex; } </code></pre> <p>I have not found any specific solution on Internet then I have posted this solution.</p> <p>Good Luck :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload