PDA

View Full Version : Sane sample app gives different results on pseudo QT terminal and on gnome-terminal



sniegu84
6th February 2016, 13:06
Hi All,
I wrote sample code that uses sane library to communicate with my scanner.

//#include <QCoreApplication>
#include <iostream>
#include <sane/sane.h>
#include <stdio.h>
using namespace std;

int sane_backend_versioncode;
const SANE_Device **devlist=NULL;
int num_of_devs;

int main(int argc, char *argv[])
{
sane_init(&sane_backend_versioncode, NULL);

sane_get_devices(&devlist, SANE_FALSE );

for (num_of_devs = 0; devlist[num_of_devs]; ++num_of_devs);

if (num_of_devs > 0) /* devices available */
{
std::cout << "Number of scan devices is " << num_of_devs <<".\n";
}
else
{
std::cout << "Number of scan devices is 0";
}

sane_exit();


cout << "" << endl; // prints
return 0;
}

What I get from Qt Creator is surprising. On its pseudo terminal I get message "Number of scan devices is 0" however when I execute the same compiled binary from gnome-terminal I get that "Number of scan devices is 1". When I created similar project in eclipse I got the same result "Number of scan devices is 1" on its pseudoterminal. Moreover when I set in Qt Creator to launch the compiled app in gnome-terminal I still have the result "Number of scan devices is 0". This was double checked and there is no space for my error.
Do you know what is going on? When Qt creator launches app it returns almost immediately with result "Number of scan devices is 0". When "Number of scan devices is 1" is returned it is after couple of seconds so after expected scanning. The result of 0 detected devices is in release and debug binary.

I attached my qt sample app with the above code. I think that it a fault of Qt pseudo terminal. Maybe it disables something that shouldn't be.
I get that result on Ubuntu 14.04 64bit and USB connected scanner Epson Stylus CX3650. On Qt creator 5.3.1 and 5.5.1.

Thanks,
Marcin

ChrisW67
6th February 2016, 21:28
Same executable plus same environment == same behaviour.

Since we are talking about the same executable, I think you will find that the environment you have configured your Qt Creator project to provide to your running project is different from the default environment in your gnome-terminal. Different library paths, environment variables SANE_*, picking up a different run time copy of libsane etc.

Try setting SANE_DLL_DEBUG=128 in the environment to see if obvious errors arise.

sniegu84
7th February 2016, 08:57
Thank you a lot. Resolved the issue.