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?
Related
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
I'm trying to test for the presence of a string somewhere in a long webpage. Using PHPUnit's assertRegExp if the string is not found it prints out the entire page and then finishes with matches PCRE pattern "/xxxxxx/". According to the documentation I should be able to specify a message a third that will be printed out if the test fails. That message is printed, followed by the full page source. What I'd like to do is just print the message. Using Selenium in my previous apps I used assertTextPresent and it would just print out confirmation that the text was/was not found, without filling my screen.
I have tried wrapping the assertRegExp in a try-catch but it didn't change anything.
You could try assertContains() instead of assertRegexp().
PHPUnit is responsible for printing out the failed text, and this differs from one assert method to another. It just might work.
If it does not, open an issue at PHPUnit's issue tracker about PHPUnit printing too much out.
I am using the getBodyText() method to get all page content and than I use assertTextPresent() to check the presence of pattern.
$this->assertTextPresent($this->getBodyText(), 'text to find');
The solution has been positivly tested with latest phpunit 4.7.
I use assertTrue(stripos($haystack, $needle) !== false, 'Failed assertion message');
I'm creating a simple "frogger" type game with Qt Creator.
I managed to get a player that works with 4 directional keys, and a car that moves on its own across the screen. I have separate Player, Car, and Frogger class.
The Frogger class paints the images in paintEvent:
painter.drawImage(player->getRect(), player->getImage());
painter.drawImage(car->getRect(), car->getImage());
But I'm encountering a problem with trying to load a different image for the car. If I use image.load("player.png"); for both the car and the player constructors, I can see the car moving across the screen as a player image, and the player which moves according to my keys.
However if I replace the image with anything else (all images are in the same folder; I also tried adding it to Qt Creator under "Other files") such as "car.png," it doesn't seem to show up. I tried it with other images, but those don't show up for player either. Any ideas on why this might happen? I commented out my autoMove() function and nothing changes, so I don't think it's related to how I implement my move. Any ideas on what I might be missing?
I guess you can reduce the possible error locations to the procedure when you load the image. Try to confirm this by checking the return value of QImage::load:
QString path = "player.png";
bool loadSuccess = image.load(path);
qDebug() << "Image" << path << "loaded? =>" << loadSuccess;
If this will print false, check if Qt can find exactly the same path when just passing to QFile:
if(!loadSuccess)
qDebug() << " File exists? =>" << QFile::exists(path);
If this will print true, the image format can't be read by Qt. Possibly you use a non-standard PNG encoding. Are the images all from the same source? (Edited by the same image editor for example)
However, if you still get the errors even when the first debug output above always prints true, the error is somewhere else. Then it could help to give us more code of how you use the images.
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";
I don't understand how QTable::editCell() should be used. I am trying to do some error checking based on entries made by user in a QTable as mentioned in my another question.
I would like to give user an opportunity to re-edit the cell which has error. For example, if name column entry has some special characters such as '(', the user should be prompted for the error and the control should go back to same cell in edit mode. I tried using QTable::editCell() in my code as shown below.
Table->editCell(row, 0, TRUE);
name = Table->text(row, 0);
However, this doesn't work as expected. The control doesn't stay in the cell at all and obviously the name is not correctly collected. So, my question is how to ensure from within code that a cell of QTable can be edited so that the edited contents can be accessed immediately in next statement (as shown in above code).
Note: I am working with qt 3.3.8 only.
I don't think you can do that. You'll have to go back to the event loop, and wait for one of the signals (like valueChanged(row,col)) to be fired to re-validate the data.
A blocking wait on a GUI object is often not a good approach (except for modal dialogs).
I know I'm a little late here but you should use the following connect statement with your own custom function to do your specific needs such as below. You can also use this method to disable users from entering in special characters within you custom function. That way they wont ever have to correct undesirable characters.
connect(ui->tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(customFunction(int,int)));
void updateTable
{
//remove invalid characters
}