I have a huge extent report which shows results basis on a loop.
Sample code:
String[] values = {"1","2".....upto 1000};
for(int i =0; i < values.length; i++) {
log("comparison started for " + i+1);
if(s.contains("abc")) {
log( i + "Success for " + s)
} else {
log(i + "Fail for " + s)
}
Now in report it shows all Pass/Fail which makes the report very heavy/ bulkier.
I want to create an expand/collapse icon next to :
log("comparison started for " + i+1);
So that, for each loop, the information remain hidden, until expanded in report.
Related
I am working with the skiasharp on xamarin with TouchTracking and while trying to handle the TouchAction event in code, i noticed the event gets fired twice instead of once.
void OnTouchEffectAction(object sender, TouchActionEventArgs args)
{
// Get touchpoint location
pt.X = XamDIUConvertToPixels(args.Location.X);
pt.Y = XamDIUConvertToPixels(args.Location.Y);
// Display point locations
Console.WriteLine("location X: " + pt.X + "\n location Y: " + pt.Y + "\n");
So, this would inevitably display to the console twice. And this becomes more problematic if say i want to call a function of text-to-speech in here, then the speech gets repeated.
I am trying to drop some mime encoded text onto a tree view. It is working - the dropMimeData() method is called, I can decode the mime data into the strings that were dropped, I can insert a child into the model which shows up in the view, but ... I can't find a way to set the text value of the new item/row to the string dragged and dropped (or any string for that matter).
Here is some of the code i've tried inside the dropMimeData() method:
if ( ( row == -1) && (column == -1) && parent.isValid() ) {
int mdlidx = this->data(parent, Qt::DisplayRole).ModelIndex;
qDebug() << "mdlidx: " << mdlidx;
// treet text - the text of the cell that gets dropped onto
QString tt = this->data(parent, Qt::DisplayRole).toString();
qDebug() << "tree text: " << tt;
TreeItem *item = this->getItem(parent);
int ccnt = item->childCount();
qDebug() << "ccnt: " << ccnt ;
if ( item->insertChildren(0, 1, 0) ) {
qDebug() << "Child Inserted";
// how do I access the new child item here ???
} else {
qDebug() << "Failed";
}
How do I access the new child item in order to set the text that would be visible in the view?
I'm using the QStandardItemModel, if that makes any difference.
My solution to this is to create a signal and slot - I emot the signal in the dropMimeData() method and the slot is in a part of the code that has the view and model, so can easily update the model.
I send the mime data and the parent across using the signal.
I'm not sure if this is the correct way of doing this, but it is working.
I'm having trouble with QSqlQuery: it's not updating my SQLite database.
I initialize the database like this (which works fine):
myDB = QSqlDatabase::addDatabase("QSQLITE");
myDB.setDatabaseName(QDir::homePath() + QDir::separator() + "file.db");
myDB.open();
if(!myDB.tables().contains("presets")) {
myDB.exec("CREATE TABLE presets (id INTEGER PRIMARY KEY ASC, path TEXT);");
for (int i=0; i<10; i++)
myDB.exec("INSERT INTO presets (path) VALUES ('n/a')");
}
I have a QString array of values that I want to update into there.
QString presets[10];
preset[0] = "foo";
preset[1] = "bar";
...
I try to update the database with a for loop like this:
QSqlQuery qPreset(myDB);
qPreset.prepare("UPDATE presets SET path=':path' WHERE id=':id';");
for (int i=0; i<10; i++){
qPreset.bindValue(":path", presets[i]);
qPreset.bindValue(":id", i+1);
qPreset.exec();
}
But nothing happens in the database and I don't get any error messages either. Any ideas why?
Edit:
This (ugly as it is) works perfectly fine though, so it's not the connection:
for (int i=0; i<10; i++)
myDB.exec("UPDATE presets SET path='" + presets[i] + "' WHERE id='" + QString::number(i+1) + "';");
Based on the question from #Nejat I have figured out the answer: I had to remove all the single quotes. I failed to notice that QSqlQuery::bindValue() takes care of all the quoting that's necessary.
Working snippet:
qPreset.prepare("UPDATE presets SET path=:path WHERE id=:id;");
Thanks for the hint.
in my program a simple shopping application for my lab exercise, i just calculated the price of items inside a for loop but when i try to print it outside it is not getting printed...pls give me some suggestion.
for (int i = 1; i < 7; i++) {
String selection = request.getParameter("a" + i);
if (selection.equals("l")) {
price = Integer.parseInt(request.getParameter("b" + i));
total = total + price;
out.println("<h3>You have purchased the item:<br>Price is:</h3>" + price);
}
}
out.println("THE TOTAL IS"+total);
out.println("</body>");
out.println("</html>");
String selection = request.getParameter("a" + i);
//Here print the selection there is the problem
if (selection.equals("l")) ///Here alway it is false thats why you are getting this.
{
}
It gets not printed because its out of scope. Your total
variable only lives within the loop.
You have basic programming skills and know about variable scope, right?
http://www.java-made-easy.com/variable-scope.html
So im a pretty new programmer so forgive me if i make any mistakes.
I need to make a higher or lower game for my class but im a little bit stuck now.
The purpose of this whole game is to guess the number which is random generated by the computer. But here's the tricky part, the user only needs to get 8 chances to guess the number right. If not the game must end and print something like: you lost, the number was.....
I came this far;
public static void main(String[] args) {
int timesGuessed = 0;
int randomNummer = (int)(Math.random()*100);
int number;
boolean won = true;
Scanner input = new Scanner(System.in);
do{
System.out.print("Guess the number: ");
number = input.nextInt();
timesGuessed++;
if(timesGuessed == 8){
won = false;
}
if(number > randomNummer){
System.out.println("Lower!");
}
else if(number < randomNummer){
System.out.println("Higher!");
}
}
while(number != randomNummer);
if(won == true){
System.out.println("The number is guessed right in " + timesGuessed + " attemts.");
}
else{
System.out.println("You lost. The number was " + randomNummer + ".");
}
}
Now the game lets you finish even though you already had 8 chances. Thats what i want to change. It needs to stop when you failed the eight time.
Thank you for the help, it would be very appreciated.
You also need to check your won variable in the condition of your loop. You may also want to add an else so it doesn't print "Higher" or "Lower" after the final try.