Results 1 to 8 of 8

Thread: Absurd behaviour with QstatusBar's showMessage

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Absurd behaviour with QstatusBar's showMessage

    Hello,

    I am wirting a fingerprint reader app, and i am using api of Secugen. Actually i have no problem with the api. I can read fingerprint images succesfully. But when i want to show some messages on status bar , some of the text is being truncated. I mean; if i want to write " CreateTemplate() failed. Error = 12" on status bar, it is written something like " ) failed. Er ". The truncation is random; sometimes from the beginning and sometimes from the end. The problem doesnt look like related to QStatusBar only. The same problem occurs when i try to setText on a Qlabel or on a QLineEdit.

    That is really annoying. I have no clue about the solution. May the secugen api cause some inconsistency in QT. Here is my code, thanks in advance... : (by the way; i am using msvc compiler with qt 4.8.1)

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QDebug>
    4. #include <windows.h>
    5.  
    6. #define REG_IMG_QUALITY 70
    7. #define VRF_IMG_QUALITY 50
    8.  
    9.  
    10. bool g_CapturedR1, g_CapturedR2, g_CapturedV1;
    11. int SecurityLevel[9]= {SL_LOWEST, SL_LOWER, SL_LOW, SL_BELOW_NORMAL, SL_NORMAL, SL_ABOVE_NORMAL, SL_HIGH, SL_HIGHER, SL_HIGHEST};
    12.  
    13.  
    14. MainWindow::MainWindow(QWidget *parent) :
    15. QMainWindow(parent),
    16. ui(new Ui::MainWindow)
    17. {
    18. ui->setupUi(this);
    19.  
    20. m_DibCtl = NULL;
    21. m_ImgBuf = NULL;
    22. m_FetBuf1 = NULL;
    23. m_FetBuf2 = NULL;
    24. m_FetBufM = NULL;
    25. m_ImageWidth = 0;
    26. m_ImageHeight = 0;
    27. m_MaxTemplateSize = 0;
    28.  
    29. g_CapturedR1 = g_CapturedR2 = g_CapturedV1 = false;
    30.  
    31. ui->m_CBDevName->addItem("USB FDU03");
    32. ui->m_CBDevName->addItem("USB FDU02");
    33. ui->m_CBDevName->addItem("Parallel FDP02");
    34.  
    35. ui->m_TemplateFormat->addItem("SG400");
    36. ui->m_TemplateFormat->addItem("ANSI378");
    37.  
    38. ui->m_SecureLevel->addItems(QStringList()<<"1 Lowest"<<"2 Lower"<<"3 Low"<<"4 Below Normal"<<"5 Normal"<< "6 Above Normal"<<"7 High"<<"8 Higher"<< "9 Highest");
    39.  
    40. ui->cR2lbl->setScaledContents(true);
    41. ui->cR1lbl->setScaledContents(true);
    42.  
    43. ui->m_TemplateFormat->setCurrentIndex(0);
    44. ui->m_SecureLevel->setCurrentIndex(4);
    45. DWORD err = SGFPM_Create(&m_hFPM);
    46.  
    47. }
    48.  
    49. MainWindow::~MainWindow()
    50. {
    51. delete ui;
    52. }
    53.  
    54. void MainWindow::on_Initbutton_clicked()
    55. {
    56.  
    57. DWORD err;
    58. DWORD devname = SG_DEV_FDU03;
    59. DWORD devid = 255; // Auto detect
    60.  
    61. QString devstr;
    62. devstr = ui->m_CBDevName->currentText();
    63.  
    64. if (devstr == "USB FDU03") // USB: FDU03
    65. devname = SG_DEV_FDU03;
    66. else if (devstr == "USB FDU02") // USB: FDU02
    67. devname = SG_DEV_FDU02;
    68. else if (devstr == "Parallel FDP02") // USB: FDP02
    69. devname = SG_DEV_FDP02;
    70.  
    71. err = SGFPM_Init(m_hFPM, devname);
    72.  
    73. if (err != SGFDX_ERROR_NONE)
    74. {
    75. this->statusBar()->showMessage( "Initialization Failed. Error = "+QString::number( err));
    76. return;
    77. }
    78.  
    79. err = SGFPM_OpenDevice(m_hFPM, devid);
    80.  
    81. if (err != SGFDX_ERROR_NONE)
    82. {
    83. this->statusBar()->showMessage( "OpenDevice() failed. Error = "+QString::number( err));
    84. return;
    85. }
    86.  
    87. SGDeviceInfoParam device_info;
    88. err = SGFPM_GetDeviceInfo(m_hFPM, &device_info);
    89.  
    90. if (err != SGFDX_ERROR_NONE)
    91. {
    92. this->statusBar()->showMessage( "GetDeviceInfo() failed. Error = "+QString::number( err));
    93. return;
    94. }
    95.  
    96. m_ImageWidth = device_info.ImageWidth;
    97. m_ImageHeight = device_info.ImageHeight;
    98.  
    99.  
    100. if (m_ImgBuf == NULL)
    101. m_ImgBuf = new BYTE[m_ImageWidth*m_ImageHeight];
    102.  
    103. // Initialize minutiae buffer
    104. err = SGFPM_GetMaxTemplateSize(m_hFPM, &m_MaxTemplateSize);
    105.  
    106. if (err != SGFDX_ERROR_NONE)
    107. {
    108. this->statusBar()->showMessage( "GetMaxTemplateSize() failed. Error = "+QString::number( err));
    109. }
    110.  
    111. if (m_FetBuf1)
    112. delete [] m_FetBuf1;
    113. m_FetBuf1 = new BYTE[m_MaxTemplateSize];
    114.  
    115. if (m_FetBuf2)
    116. delete [] m_FetBuf2;
    117. m_FetBuf2 = new BYTE[m_MaxTemplateSize];
    118.  
    119. if (m_FetBufM)
    120. delete [] m_FetBufM;
    121. m_FetBufM = new BYTE[m_MaxTemplateSize];
    122.  
    123. this->statusBar()->showMessage( "Initialization SuccessÄŸ");
    124.  
    125. ui->m_CapBtnV1->setEnabled(true);
    126. ui->m_ConfigBtn->setEnabled(true);
    127. ui->BtnCaptureR1->setEnabled(true);
    128. ui->BtnCaptureR2->setEnabled(true);
    129. ui->m_FormatBtn->setEnabled(true);
    130.  
    131. }
    132.  
    133. void MainWindow::on_BtnCaptureR1_clicked()
    134. {
    135.  
    136. // Capture fingerprint
    137. qDebug()<<"Capturing";
    138.  
    139. QImage cImage;
    140.  
    141. DWORD err = SGFPM_GetImageEx(m_hFPM, m_ImgBuf, 5000, NULL, REG_IMG_QUALITY);
    142.  
    143. if (err == SGFDX_ERROR_NONE)
    144. {
    145. cImage = QImage((const unsigned char*)(m_ImgBuf), m_ImageWidth, m_ImageHeight, QImage::Format_Indexed8);
    146. QPixmap cPixmap;
    147. cPixmap.convertFromImage(cImage);
    148. ui->cR1lbl->setPixmap(cPixmap);
    149. DWORD img_qlty;
    150. err = SGFPM_GetImageQuality(m_hFPM, m_ImageWidth, m_ImageHeight, m_ImgBuf, &img_qlty);
    151.  
    152. // // Extract Fingerprint
    153. err = SGFPM_CreateTemplate(m_hFPM, 0, m_ImgBuf, m_FetBuf1);
    154. if (err == SGFDX_ERROR_NONE)
    155. {
    156. g_CapturedR1 = true;
    157. this->statusBar()->showMessage("The first template is created. Image Quality= "+ img_qlty);
    158. }
    159. else{
    160. this->statusBar()->showMessage(QString::fromUtf8(" CreateTemplate() failed. Error = ")+ QString::number(err));
    161.  
    162. }
    163. }
    164. else{
    165. this->statusBar()->showMessage(QString("The captured image is not good. Try again...Err:")+QString::number(err));
    166. }
    167.  
    168. if (g_CapturedR1 && g_CapturedR2)
    169. {
    170. ui->m_RegisterBtn->setDisabled(false);
    171. }
    172.  
    173. // UpdateData(false);
    174. }
    175.  
    176.  
    177. void MainWindow::on_BtnCaptureR2_clicked()
    178. {
    179. // Capture fingerprint
    180. DWORD img_qlty;
    181. DWORD err = SGFPM_GetImageEx(m_hFPM, m_ImgBuf, 5000, NULL, REG_IMG_QUALITY);
    182.  
    183. if (err == SGFDX_ERROR_NONE)
    184. {
    185. QImage cImage;
    186. cImage = QImage((const unsigned char*)(m_ImgBuf), m_ImageWidth, m_ImageHeight, QImage::Format_Indexed8);
    187. QPixmap cPixmap;
    188. cPixmap.convertFromImage(cImage);
    189. ui->cR2lbl->setPixmap(cPixmap);
    190. err = SGFPM_GetImageQuality(m_hFPM, m_ImageWidth, m_ImageHeight, m_ImgBuf, &img_qlty);
    191.  
    192. // Extract Fingerprint.
    193. err = SGFPM_CreateTemplate(m_hFPM, 0, m_ImgBuf, m_FetBuf2);
    194.  
    195. if (err == SGFDX_ERROR_NONE)
    196. {
    197. this->statusBar()->showMessage("The second template is created. Image Quality= "+ img_qlty);
    198. g_CapturedR2 = true;
    199. }
    200. else
    201. {
    202. this->statusBar()->showMessage("CreateTemplate() failed. Error = "+ QString::number(err));
    203. }
    204. }
    205. else
    206. {
    207. this->statusBar()->showMessage("The captured image is not good. Try again...");
    208. }
    209.  
    210. if (g_CapturedR1 && g_CapturedR2)
    211. {
    212. ui->m_RegisterBtn->setDisabled(false);
    213. }
    214.  
    215. }
    216.  
    217. void MainWindow::on_m_CapBtnV1_clicked()
    218. {
    219. // Capture fingerprint
    220. DWORD img_qlty;
    221. DWORD err = SGFPM_GetImageEx(m_hFPM, m_ImgBuf, 5000, ui->cv1lbl->winId(), VRF_IMG_QUALITY);
    222. if (err == SGFDX_ERROR_NONE)
    223. {
    224. err = SGFPM_GetImageQuality(m_hFPM,m_ImageWidth, m_ImageHeight, m_ImgBuf, &img_qlty);
    225.  
    226. // Extract Fingerprint.
    227. err = SGFPM_CreateTemplate(m_hFPM, 0, m_ImgBuf, m_FetBufM);
    228. if (err == SGFDX_ERROR_NONE)
    229. {
    230. g_CapturedV1 = true;
    231. this->statusBar()->showMessage("The template for verification and identification. Image Quality="+QString::number( img_qlty));
    232. }
    233. else
    234. {
    235. this->statusBar()->showMessage("CreateTemplate() failed. Error = "+QString::number(err));
    236. }
    237.  
    238. }
    239. else
    240. {
    241. this->statusBar()->showMessage("The captured image is not good. Try again...");
    242. }
    243.  
    244.  
    245. if (g_CapturedR1 && g_CapturedR2 && g_CapturedV1)
    246. {
    247. ui->m_VerifyBtn->setDisabled(false);
    248. ui->m_IdentifyBtn->setDisabled(false);
    249. }
    250. }
    251.  
    252. void MainWindow::on_m_FormatBtn_clicked()
    253. {
    254. WORD template_format;
    255. if (ui->m_TemplateFormat->currentIndex() == 0)
    256. template_format = TEMPLATE_FORMAT_SG400;
    257. else
    258. template_format = TEMPLATE_FORMAT_ANSI378;
    259.  
    260. DWORD err = SGFPM_SetTemplateFormat(m_hFPM, template_format);
    261. if (err == SGFDX_ERROR_NONE){
    262. //this->statusBar()->showMessage("SetTemplateFormat() Success");
    263. }
    264. else
    265. {
    266. //this->statusBar()->showMessage("SetTemplateFormat() failed. Error = "+ QString::number(err));
    267. }
    268. }
    269.  
    270. void MainWindow::on_m_RegisterBtn_clicked()
    271. {
    272. if ((m_FetBuf1 == NULL) || (m_FetBuf2 == NULL))
    273. return;
    274.  
    275. BOOL matched;
    276. DWORD err = SGFPM_MatchTemplate(m_hFPM, m_FetBuf1, m_FetBuf2, SecurityLevel[ui->m_SecureLevel->currentIndex()], &matched);
    277.  
    278. if ((err == SGFDX_ERROR_NONE) && matched)
    279. {
    280. QFile dFile(ui->uName->text()+".min");
    281. if(dFile.open(QIODevice::ReadWrite))
    282. {
    283. dFile.write((const char *)m_FetBuf1,400);
    284. dFile.write((const char *)m_FetBuf2,400);
    285. dFile.close();
    286. }
    287. DWORD match_score;
    288. err = SGFPM_GetMatchingScore(m_hFPM, m_FetBuf1, m_FetBuf2, &match_score);
    289. this->statusBar()->showMessage("Registration Success : Matching Score ="+ match_score);
    290. }
    291. else{
    292. this->statusBar()->showMessage("Registration Fail");
    293. }
    294.  
    295. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Absurd behaviour with QstatusBar's showMessage

    When you reduce the claimed problem to a minimal example you'll quickly find the problem is not Qt:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MainWindow: public QMainWindow {
    4. Q_OBJECT
    5. public:
    6. MainWindow(QWidget *p = 0): QMainWindow(p) {
    7. QWidget *central = new QWidget(this);
    8. QVBoxLayout *layout = new QVBoxLayout(this);
    9. m_label = new QLabel(this);
    10. m_lineEdit = new QLineEdit(this);
    11. layout->addWidget(m_label);
    12. layout->addWidget(m_lineEdit);
    13. central->setLayout(layout);
    14. setCentralWidget(central);
    15. resize(640, 480);
    16. m_count = 0;
    17. QTimer *t = new QTimer(this);
    18. t->start(1000);
    19. connect(t, SIGNAL(timeout()), SLOT(doit()));
    20. }
    21. public slots:
    22. void doit() {
    23. statusBar()->showMessage("I am a status bar " + QString::number(++m_count));
    24. m_lineEdit->setText("I am a line edit " + QString::number(++m_count));
    25. m_label->setText("I am a label " + QString::number(++m_count));
    26. }
    27. private:
    28. QLabel *m_label;
    29. QLineEdit *m_lineEdit;
    30. int m_count;
    31. };
    32.  
    33. int main(int argc, char *argv[])
    34. {
    35. QApplication app(argc, argv);
    36. MainWindow m;
    37. m.show();
    38. return app.exec();
    39. }
    40. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    Did SGFPM_Create() succeed?

  3. #3
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Absurd behaviour with QstatusBar's showMessage

    Thanks Chris, actually i also think that the problem is not Qt. I have written lots of apps like this without any problems before . But i am worrying if some external libraries like this one cause some problems with Qt in rare cases ? If yes, is there any solution. For example i've heard that boost library has some problems when working with Qt. By the way, SGFPM_Create() succeds, no problem with it.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Absurd behaviour with QstatusBar's showMessage

    If the external library is trashing memory there's nothing much can be done other than fix the library.

    The reason I asked if SGFPM_Create() succeeds is that if you continue after it failed you may well find the library assuming the handle is correctly initialised and doing odd things to memory outside itself as a result. You don't check the return code in the code you posted but the docs I see are light on that too. Try initialising m_hFPM to zero in the constructor before you call SGFPM_Create().

    Also I don't see your MainWindow destructor cleaning up with SGFPM_Terminate(). Perhaps after several unterminated runs the library loses the plot? Does it happen the first time you run it on a freshly booted machine?

  5. #5
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Absurd behaviour with QstatusBar's showMessage

    SGFPM_Create() returns SGFDX_ERROR_NONE , no problem with it. Initialising m_hFPM to 0 didn't make ant difference. The problem occurs any time including fresh boot.

    The visual c++ mfc version of the application using the api works without any problem.. Stuck..

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Absurd behaviour with QstatusBar's showMessage

    For example i've heard that boost library has some problems when working with Qt.
    I use the boost templates extensively in my Qt apps (particularly smart pointers and including some difficult ones like boost::graph) and have also used parts of loki. I have never seen any problem or error related to either of these except those due to my own programming mistakes (which I must say occur only very rarely... )

    If I were to guess, the problems you might have heard about are probably due to misuse of QObject instances with smart pointer wrappers or containers which do not respect the parent - child ownership and lifetimes used in Qt.
    Last edited by d_stranz; 31st May 2012 at 20:46.

  7. #7
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Absurd behaviour with QstatusBar's showMessage

    When i change

    Qt Code:
    1. this->statusBar()->showMessage("The first template is created. Image Quality= "+ img_qlty);
    To copy to clipboard, switch view to plain text mode 

    to:

    Qt Code:
    1. this->statusBar()->showMessage("The first template is created. Image Quality= "+ QString::number(img_qlty));
    To copy to clipboard, switch view to plain text mode 

    the problem looks solved. But i dont know why any error or warning isnt given when appending dword to QString, there is no such operator i think. Thanks, anyway...

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Absurd behaviour with QstatusBar's showMessage

    Interesting. I only looked at the specific error message you mentioned, and it has a QString::number() call. Clearly the compiler was doing something with it though: Taking the const char * address and adding img_qlty bytes to it then using that as a string address. So your example string "CreateTemplate() failed. Error = " + 12 was offset by 12 bytes to give "te() failed. Error = ". For large (or negative) values of img_qlty you may find ourself stepping completely out of the intended string and into the next in data section or crashing the program.

    I'd be inclined to do this:
    Qt Code:
    1. QString("The first template is created. Image Quality %1").arg(img_qlty);
    2. //or
    3. tr("The first template is created. Image Quality %1").arg(img_qlty);
    To copy to clipboard, switch view to plain text mode 
    as a precaution against the similar errors.

Similar Threads

  1. Replies: 2
    Last Post: 28th January 2010, 16:47
  2. QStatusBar
    By newermind in forum Qt Programming
    Replies: 3
    Last Post: 1st June 2009, 21:48
  3. QSystemTrayIcon::showMessage
    By radojkod in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 13:13
  4. absurd problem
    By sabonis in forum General Programming
    Replies: 1
    Last Post: 3rd March 2008, 22:52
  5. about QStatusBar
    By Pang in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2006, 04:15

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.