Archiwum kategorii: In English

Examples of QString::number

Some examples of a very useful Qt function: QString::number. This function is helpful in converting double/float to string. QString, to be more precise 😉

QString::number has got 3 parameters:

  • double n – number, which will be converted
  • char format = 'g – format: available formats are f, e, E, g, G. Default is 'g’:
  • int precision = 6 – precision.

QString::number – examples

Let me show some examples. On the end of each line is a output from console:

//f - float
QString::number(3.14159265359, 'f', 0); //3
QString::number(3.14159265359, 'f', 1); //3.1
QString::number(3.14159265359, 'f', 2); //3.14
QString::number(3.14159265359, 'f', 15);//3.141592653590000

//e - exponential notation
QString::number(3.14159265359, 'e', 15); //3.141592653590000e+00
QString::number(3.14159265359, 'E', 15); //3.141592653590000E+00

//g/G - "general" - in this case: "f"
QString::number(3.14159265359, 'g', 0); //3
QString::number(3.14159265359, 'g', 1); //3
QString::number(3.14159265359, 'g', 2); //3.1
QString::number(3.14159265359, 'g', 15); //3.14159265359

QString::number(3.14159265359, 'G', 2); //3.1
QString::number(3.14159265359, 'G', 15); //3.14159265359

//g/G - "general" - in this case: "e/E"
QString::number(2.5e+5, 'g', 0); //2e+05
QString::number(2.5e+5, 'g', 1); //2e+05
QString::number(2.5e+5, 'g', 2); //2.5e+05
QString::number(2.5e+5, 'g', 15); //250000

QString::number(2.5e+5, 'G', 2); //2.5E+05
QString::number(2.5e+5, 'G', 15); //250000

//comparision with f and e/E:
QString::number(2.5e+5, 'f', 2); //250000.00

QString::number(2.5e+5, 'e', 15); //2.500000000000000e+05
QString::number(2.5e+5, 'E', 2); //2.50E+05

How to run tests in Visual Studio?

How to run tests (unit tests, Selenium or any other in Microsoft Visual Studio? This is quite simple.

My instruction is for Visual Studio Professional 2015.

  1. First – choose test runner (nUnit, MSTest, xUnit or other). I choosed nUnit, because of its popularity.
  2. Install a test runner. I use NuGet to manage dependencies in my projects. To install nUnit, click (right) on project and click „Manage NuGet Packages”, search „nUnit” and install it. A current version number is 3.4.1.
  3. Prepare a simple test. Remember about:
    • making class containing tests public (public class TestClass{})
    • making test methods public (public void TestMethod(){})
    • marking test methodss with [Test] attribute.
  4. Prepared test should be visible in Test Explorer (open this window from menu: Test -> Windows -> Test Explorer). If Test Explorer window is empty and after building project Visual Studio doesn’t display any tests, you need to install nUnit Test Adapter (version 3.x is compatible with nUnit 3.x). To install nUnit Test Adapter, choose „Extensions and Updates” from „Tools” menu, search for „nUnit Test Adapter” and install it. After rebooting Visual Studio and rebuilding project, tests should be displayed in Test Explorer Window.

How to install LHAPDF6

Instruction how to install LHAPDF6 is easy to find here: But on „fresh” Linux you need to install some dependencies. This tutorial will be about installing additional dependencies needed by LHAPDF6.

How to install LHAPDF6?

Foto: mine. 2008?


Download LHAPDF archive from page and unpack to any directory. Alternative method is to use wget:

tar xf LHAPDF-6.1.6.tar.gz
cd LHAPDF-6.1.6

Czytaj dalej

How to check if element is invisible in Ruby Selenium client

How to check if element is invisible in Ruby Selenium client? In Java or C# answer is easy. There is a mechanism called ExpectedCondition, which has got ready for use method: ExpectedConditions.invisibilityOfElementLocated. Example:


Unfortunatelly, Ruby client hasn’t got anything like this. Quick workaround – try to find element. When element is not displayed, catch exception and return false:

def check_if_not_exist(locator)
    wait = :timeout => 10
    wait.until { @driver.find_element(:name, 'elementName').displayed? }

Not very elegant and quick, but works.


Selenium: Exception „Compound class names are not supported”

Today something about one of exceptions that can occure in Selenium PageFactory.

IllegalLocatorException was unhadled by user code.
An exception of type „OpenQA.Selenium.IllegalLocatorException” occured in WebDriver.dll but was not handled in user code.
Additional information: Compound class names are not supported. Consider searching for one class name and filtering the results.

In my case, this exception was thrown in line:

PageFactory.InitElements(webDriver, pageElement);

This is probably a bug in Selenium. Solution is easy: just do not use:

[FindsBy(How=How.ClassName, Using="name_of_class"]

Instead of ClassName, try to use Css Selectors:

[FindsBy(How=How.CssSelector, Using=".name_of_class"]

Remember about a dot!

Ruby: hash as argument

What will Ruby do, when we pass hash as argument to function? Let’s see.

We have method – with definied default value (empty hash):

def foo(hashh = {})
  puts 'Is hash empty? ' + hashh.empty?.to_s,""

1. When we invoke function with any hash, it will be passed into method. Output? „Is hash empty? false„.

foo({:id => 'someid'})

h = {:id => 'first', :name => 'noname'}

2. When we invoke function without any parameter, Ruby will take default value – empty hash. Output is „Is hash empty? true„.


3. Of course, when we pass nil to function, we will got exception: „undefinied method ’empty’ for nil:NilClass„.


How to debug remote application on Tomcat

Some time ago I wrote about a situation when starting of Tomcat from Netbeans failed. Of course when someone follows with steps prepared in this article, debugging is more complicated. But there is one nice feature in Tomcat – we can debug remote servers.

First thing to do is to enable debugging applications deployed on Tomcat, start Tomcat by this way:

Tomcat/bin/catalina.bat jpda start

By default, Tomcat is listening on port 8000 (changing default port is possible in some configuration files).

In second step we should connect from Netbeans to our application. Sources in IDE (in my case: Netbeans) must be identical with classes deployed on Tomcat! If there are any differences, some breakpoints will be unavailable and debugging will not working properly.

Go to Debug menu and fill forms:

Debugger: Java Debugger (JPDA)
Connector: SocketAttach
Port: 8000

and click OK. After a while, breakpoints should be available. Look into console. There are info about enabling each breakpoint.

Starting of Tomcat failed

Some day I had problem with deploying project from Netbeans to Tomcat (you may look to similar discussion on StackOverflow: Starting of Tomcat failed from Netbeans 7.3). Unfortunatelly, any of suggestion didn’t help, so I wrote my own deployer in Windows batch.

Some code:

ECHO AutoDeploy to Tomcat

SET tomcat_path=C:\TOMCAT
SET build_path=D:\SVN\SMOK_ELTE\JAVA\amfgw\build\web\WEB-INF\classes

::Stop Tomcat
echo Stop Tomcat, press any key to continue...

netstat -a -n | findstr :8080 > NUL
if %errorlevel%==0 ( goto :stoptomcat ) else ( goto :next )
echo Closing Tomcat.
call %tomcat_path%\bin\shutdown.bat
goto :next

::Copy compiled classes from Netbeans to Tomcat
XCOPY %build_path% "%tomcat_path%\webapps\ROOT\WEB-INF\classes" /E /C /R /I /K /Y

::Run Tomcat
CALL %tomcat_path%\bin\catalina.bat jpda start

But I wanted more – let Netbeans run this script after building my application.

Edit build.xml file, located in project directory, by putting these lines:
<target name="-post-compile">
<exec dir="." executable="cmd">
<arg line="/c D:\scriptLocation\deployOnTomcat.bat"/>

Netbeans doesn’t start

Sometimes after installation new plugins to Netbeans, if plugins are not compatible, Netbeans can’t run.  Unfortunatelly, deleting these new files from Netbeans directory didn’t helps. So what can we do?

One thing is to open configuration file and disable new plugin.

In Windows7, go to location:


and find this file, for example:


Try to disable this plugin by putting „false” in tags:

<param name="autoload">false</param>
<param name="eager">false</param>
<param name="enabled">false</param>

If disabling plugins didn’t helps, try to delete all Netbeans configuration by deleting directories (before deleting, you can make a copy of these files):


Unfortunatelly, this operation removes all configurations (servers, loaded projects and other).