I have follwing code snippet to run. In which I want to see result of qDebug() but I dont want see result of qInfo(). I want to configure it on basis, sowetimes I need those qInfo() output and sometimes not.
qInfo()<<"Info print";
qDebug()<<"Debug print";
In above code, I want only 'Debug print' should print. but can't comment qInfo() line.
As it described on the Qt debug documentation, you have to compile with QT_NO_INFO_OUTPUT to disable it.
# your .pro file
DEFINES += QT_DEPRECATED_WARNINGS QT_NO_INFO_OUTPUT
You can also use define for other macro:
qDebug(): disable with QT_NO_DEBUG_OUTPUT
qInfo(): disable with QT_NO_INFO_OUTPUT
qWarning(): disable with QT_NO_WARNING_OUTPUT
qCritical(): enable with QT_FATAL_CRITICALS
You can choose at runtime which category enable (even for custom category) with QLoggingCategory::setFilterRules
From Qt Docs, exampe with custom category:
QLoggingCategory::setFilterRules(QStringLiteral("driver.usb.debug=true"));
For your case:
QLoggingCategory::setFilterRules(QStringLiteral("*.info=false"));
take care of using "*.info=true" because enable everything, even for profiling category usually disablet
Related
I log errors using QLoggingCategory stuff. Every time I have to use .noquote():
qCWaning(appCategory).noquote()
<< QCoreApplication::translate("app", "Unable to create object from URL %1")
.arg(url.toString());
to disable "" quotes inserted around message text.
Is it possible to make every instance of QDebug created by QMessageLogger's methods to be .noquote() by default?
Surely I can make #defines for every kind of message category. But is there global settings for that?
While in a terminal session I can do
:set textwidth=9999
And I receive what I want (which is lines of text which can go to the end of my computer screen)
I created a file called ~/.vimrc which contains the line
set textwidth=9999
And I get no results from from this
Your ~/.vimrc is loaded as the very first configuration (cp :help initialization); after that, other configuration and plugins are read, and any of those may change the option again. You can check with
:verbose set textwidth?
and get the list of configuration scripts via
:scriptnames
Ideally, you're able to disable the overriding of the option value. As a workaround, you can also re-initialize the option at the end of configuration, by putting the following into your ~/.vimrc:
autocmd VimEnter * set textwidth=9999
The 'textwidth' option is a buffer-local option. Filetype plugins may adapt this setting. There are ways to override filetype-specific settings (:help after-directory), too.
I'm making an application part of which is reading from an XML which stores some preferences. However, whenever I build the project, all the sources get copied but the preferences file does not! I have added the following to the .pro file -
RESOURCES += rsc.qrc
And my rsc.qrc contains
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>data/preferences.xml</file>
<file>data/gamedata.xml</file>
</qresource>
</RCC>
Now whenever I try to open preferences.xml
QFile preferences(":/data/preferences.xml");
if(!preferences.exists()){
preferences.open(QFile::WriteOnly);
preferences.write("abc");
qDebug() << "Written";
}
else {
qDebug() << "File exists";
}
Absolutely nothing gets printed and even the rest of the application stops working.
You don't use the resource part correctly in your example.
It will most likely not work because you try to write to a resource that is embedded into your executable after you have build your application. Reading is fine, but writing can't work by definition.
If you want a editable setting files, you have to distribute them along with your executable, or use a different method for reading/writing your settings like QSettings.
However using QSettings also means, that you will need to configure all your default settings in your loading function in case the values do not exist if you use the default configuration. Meaning you use registry on windows.
You have the option to force the use of a INI file format in the constructor of QSettings, this can make sense if you want to provide a default settings INI file instead of your xml files.
In case you want to store more complex data a xml file might be needed anyway, so if you want to stick with that you will need a way to copy your setting files to your build path. This can be done within your pro file with QMAKE_POST_LINK.
Example:
COPY_CMD = "$$PWD\\data\\preferences.xml $$OUT_PWD\\release\\data\\preferences.xml"
COPY_CMD = $${QMAKE_COPY} $$replace( COPY_CMD, "/", "\\" ) $$escape_expand( \\n\\t )
QMAKE_POST_LINK += $$COPY_CMD
I am building up a QListWidget, browsing through a directory so that every ".png" gets listed with a preview icon.
The core of my populating loop looks like this:
new QListWidgetItem( QIcon(act_fullname), act_filename);
Right after the whole list is ready, the app crashes.
The error is many times repeated and says this:
On Mac OS X, you might be loading two sets of Qt binaries into the
same process. Check that all plugins are compiled against the right Qt
binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of
binaries are being loaded. QObject::moveToThread: Current thread
(0x103339cb0) is not the object's thread (0x10a848670). Cannot move to
target thread (0x103339cb0)
On Mac OS X, you might be loading two sets of Qt binaries into the
same process. Check that all plugins are compiled against the right Qt
binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of
binaries are being loaded.
Do you have any ideas?
Thanks for your help!
EDIT:
If I skip the icons there is no problem. I have also tried going
QListWidgetItem *item = new QListWidgetItem(act_filename);
ui->listWidget->addItem(item);
item->setIcon(QIcon(act_fullname));
and got no difference.
EDIT 2:
I do not call QObject::moveToThread(QThread*) I don't even use threads (deliberately at least).
Also, the errors appear to come after the loop. I have cout-ed every iteration and the end of the loop and right after my "end loop cout msg" I see that
objc[56963]: Class QCocoaColorPanelDelegate is implemented in both
/Users/Barnabas/QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/QtGui
and
/Users/Barnabas/Programming/Qt/demo_OpenCV-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Release/demo_OpenCV.app/Contents/MacOS/../Frameworks/QtGui.framework/Versions/4/QtGui.
One of the two will be used. Which one is undefined.
Here, too, I do not use QCocoaColorPanelDelegate. I don't even know what it is ... :(
But here is my more detailed code:
boost::filesystem::path p("/path/to/dir");
if(boost::filesystem::is_directory(p))
{
for(boost::filesystem::directory_iterator it(p); it!=boost::filesystem::directory_iterator(); ++it)
{
if(it->path().extension().string()==".png")
{
std::cout<< it->path() <<std::endl;
QString item_name( it->path.stem().c_str() );
QString screen_file( it->path.c_str() );
QListWidgetItem *item = new QListWidgetItem(item_name);
QIcon *icon = new QIcon(screen_file);
item->setIcon(*icon); // if I comment this one out, everything is fine.
ui->imageList->addItem(item);
}
}
}
I have also tested it with a single .png and the image was displayed properly in the list but crash followed with the very same messages.
I have finally found the solution: manually removed the Debug and the Release directories.
For those whose similar problem is not solved by this see: this link.
I'm trying to make something like plugin that outputs certain text when Qt creator runs any program. Does anyone have any idea what should I use to achieve that?
edit:
I need to make plugin that checks whether user has used appropriate style of programming. (Has put spaces where required for example) But I'm not sure how it is done so I try to start with some simple output while building.
You can use one of the debug statements:
qDebug() << "some debug info";
qWarning() << "a warning";