I was trying a few whiteboard programs, just for fun. In one of them I called a constructor from within another constructor. Code compiled without any fuss,but code didn’t worked the way I was expecting. I found out that when calling a constructor from within a constructor a temporary unnamed constructor is created. That is the reason why program is not behaving the way I was expecting. Check out this…
How many times your content editor/submitter used some wrong html rules in your site content?
For me, the answer is numerous times. I used to be anxious each and every time, he logged in. I developed a joomla based CMS site for our company, once the site is launched I moved to other projects. But every now and then they used to call me as some pages are looking different. This is because our beloved content editor has used some new kind of fonts and text rules which were not used anywhere in the site. Yes yes,I know there is tinyMCE . But problem is when you are copying from multiple sources and pasting into your article, your article(in this case I mean joomla article) becomes very clumsy. In this situation, if apply your desired style rule using tinymce , the result may not be good.
So the best way is to
- Remove all HTML styles.
- Get the clean text
- Now apply your text rules.
But again,our dear content editor may be a bit lazzy. So thats why I planned a tool for him. Its a simple two file application, you may marge it into one file too. The concept is this :
- There is a text box where he has to paste the text
- The script will remove all previous styles from the text and apply new styles as defined inside the script.
- Regular expressions matching is used to apply special rules for specific words.
What it does is :
- It removes all styling but keeps newline characters and paragraphs.
- It converts everything to arial and with the selected font size.
- it searches inside the text , and converts every occurrence of foo into a orange coloured foo. You may use this feature for your brand name.
- It also applies different styling for the title.
So thats it. Download the files. put them in your apache’s web folder and run. Please feel free to modify the codes as per your need.
I came across a line of code which looked a bit strange to me. It reads like this..
x= m * (n=7);
The above code is actually equivalent to
Actually c++ supports using assignments on the right hand side of assignments operator. And we are all familiar with that. I bet you must have seen assignments like this…
This and the previous code follows the same rule.
In our office we use stl as much as possible. Even when coding in qt we are advised to import and use stl containers. I googled this issue to know justifications behind this favourism. What I found is STL is a clear winner if speed is single most important concern. On the other hand qtl has many advantages of it’s own. Let me elaborate these points with an example of vector. QVector is more easier to use than stl::vector. Qvectors are more light weight. Whenever we copy or pass qvector , only a pointer to vector is passed. A deepcopy is used only when editing data. QVector occupies more memory to prevent use of memory allocation operations each and every time expansion is required. It uses realloc() to grow by increments of 4096 bytes. Qvector has lots of interesting functions to make the life easier for developers. It has a squeeze option to remove extra spaces allocated. So I believe it’s advisable to use qvector as much as possible. And in case you want to use stl:: vector , you can always convert to stl::vector like this
QVector vector; vector << 1.2 << 0.5 << 3.14; std::vector stdvector = vector.toStdVector();
I was searching a while for these recipes. Hope these will come handy for novice qt coders.
1. Making a cell read only.
QTableWidgetItem *item; item=new QTableWidgetItem(); item->setFlags(!Qt::ItemIsEditable);//Read about flags in api doc. ui->tw->setItem(0,1,item);
2. Adding a widget in a table cell
QComboBox *comboWidget = new QComboBox();//create any widget
comboWidget->addItems(list);//adding a string list to add values ui->tw->setCellWidget(0,0,comboWidget);//row,column,widget variable
3. Detecting type of widget in a cell
4. Adding text to a cell.
QTableWidgetItem *item; item=new QTableWidgetItem(); item->setText("HELLO WORLD"); ui->tw->setItem(1,1,item);
5.Fetching double values from a cell
double temp =ui->tw->item(row,column)->text().toDouble();6. setting width of each qt columns.ui->tableWidget->horizontalHeader()->resizeSection(columnNumber, size);7. Setting up labels for columns.QStringList list; list<<"First"<<"Second"; ui->tw->setHorizontalHeaderLabels(list);
It was required to add an identification token at the end of qstring. Do some operation based on that token and while displaying data remove that token. Here is how I did it …
(here the word <solid> excluding brackets is the token for us)
QString abb = "hello world <gh> <solid>shygdajs";//STRING TO PLAY std::cout<<abb.toStdString().data(); std::cout<<std::endl; int e= abb.lastIndexOf(">");//where <solid> ends int s= abb.lastIndexOf("<");//where <solid> starts int size = e-s;//size of token <solid> QString key = abb.mid(s+1,size-1);//extract token std::cout<<key.toStdString().data(); std::cout<<std::endl; QString m="sgdsakh sads < "; std::cout<<m.toStdString().data(); std::cout<<std::endl; m=m.trimmed();//remove white spaces from both sides std::cout<<m.toStdString().data(); std::cout<<std::endl; m = m+"<solid>";//appending data at the end std::cout<<m.toStdString().data(); std::cout<<std::endl; s=m.lastIndexOf("<"); m=m.left(s);// string without newly added data std::cout<<m.toStdString().data(); std::cout<<std::endl; I hope this code will save time for beginners. For theory you can always refer to qt's inbuilt documentation.