Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Friday, October 29, 2010

Dang, Qt Creator is slow when stepping into functions

This link seems to address the issue. This post is a placeholder, perhaps I can break a few cycles free to work on it.

Monday, April 12, 2010

linux ld.so.conf path (CentOS 5.4, RedHat)

I'm linking OpenCV into my Qt project. More samples on that later. Runtime produced this error:

"Path_to_source: error while loading shared libraries: libcv.so.2.0: cannot open shared object file: No such file or directory"

The path to the OpenCV dynamic link libraries (.so files) were not in the link library path.

Found a clue here here and here.

solution:

su root
cd /etc/ld.so.conf.d
cat > opencv-10.conf
/usr/local/lib
^c
/sbin/ldconfig -v

Friday, March 26, 2010

Unit Testing quirks: Why doesn't the makefile know how to build the ".moc" file.

I'm following the sample at the Qt site on how to make a unit test. But mine continually failed. Of course I'm less than comfortable with the two magic lines at the end of the source file:

Finally, to make our test case a stand-alone executable, the following two lines are needed:

 QTEST_MAIN(TestQString)
#include "testqstring.moc"

The QTEST_MAIN() macro expands to a simple main() method that runs all the test functions. Note that if both the declaration and the implementation of our test class are in a .cpp file, we also need to include the generated moc file to make Qt's introspection work.

Note the part at the end "if both the declaration and implementation ... are in a .cpp file." what's missing is that "if the declaration and implementation are in separate .h and .cpp files, then that final include is unnecessary."

That's the danger of having magic in the build system.

I've uploaded a sample unit test to my SkyDrive. So far I've not found any buildable projects on the web.

A little bitty Java has some good notes on Qt Unit Testing.

KDE TechBase has another intro here.

Here's a description of why the include's not necessary when there's both a header and cpp file in the test.

Wednesday, January 13, 2010

Extracting an item from a QStandardItemModel

Trial and error led me to this. I have a QListView and a QStandardItemModel. I select one of the items in the View and would like to retrieve it for use.

Need to know which row index was clicked (be sure and set the QListView selectingBehavior to "selectRows," otherwise you may get just a single item within the row). That "selectionModel()" is a tricky bit that wasn't obvious from the docs.

QModelIndexList indices = ui->treeView->selectionModel()->selectedRows();

The QListView is setup so that only a single row can be selected at a time. Verfiy that at least one row was chosen, then determine the correct row index:

if ( indices.count() == 1 )
{
  QModelIndex idx = indices[0];
  int row = idx.row();

Retrieve the model from the view:

QStandardItemModel *model =
  dynamic_cast < QStandardItemModel* >(ui->treeView->model());

QStandardItemModel allows you to retrieve a QStandardItem using integers for row and column (I got wrapped around the axle about QModelIndex from model->data(), but the createIndex() method was protected inside QStandardItemModel. We don't need that, just the integer indices)

QStandardItem *firstColumnItem = model->item(row, 0);

Internally, the object is stored as a QVariant. My two columns contain QString and QDateTime. FYI I used Qt::DisplayRole when inserting the objects into the model.

QVariant
  firstColumnVariant(firstColumnItem->data(Qt::DisplayRole));
QString
  firstColumnString(firstColumnVariant.toString());

Next, I got the second column with some shorthand:
QVariant
  dateTimeVariant(model->item(row,1) ->data(Qt::DisplayRole));
QDateTime
  dateTime(dateTimeVariant.toDateTime());

And popped it up in a MessageBox:

QMessageBox(QMessageBox::Information, firstColumnString, dateTime).exec();

QTreeView (QAbstractItemView) and PageUp/PageDown

Just a note on QTreeView and PageUp/PageDown. I'm developing an app designed for fingers on a big screen, and need a button for PageUp/PageDown rather than using the scrollbar.

QTreeView.autoScroll must be set to "true" to enable PageUp/PageDown key commands to move the list.

Monday, January 11, 2010

Build Error: C:\Qt\2009.05\mingw\bin\mingw32-make.exe: Interrupt/Exception caught (code = 0xc0000005, addr = 0x41f96e)

(I presume your addresses may vary, and I was building the "textobject" sample from the Getting Started screen.)
More text from the build error:

Running build steps for project textobject...

Starting: c:/qt/2009.05/qt/bin/qmake.exe C:/Qt/2009.05/qt/examples/richtext/textobject/textobject.pro -spec win32-g++ -r

Exited with code 0.

Starting: C:/Qt/2009.05/mingw/bin/mingw32-make.exe -w

mingw32-make: Entering directory `C:/Qt/2009.05/qt/examples/richtext/textobject'

C:/Qt/2009.05/mingw/bin/mingw32-make -f Makefile.Debug all

C:\Qt\2009.05\mingw\bin\mingw32-make.exe: Interrupt/Exception caught (code = 0xc0000005, addr = 0x41f96e)

Exited with code 255.

Error while building project textobject

When executing build step 'Make'


This happens because the installer for the MinGW Windows release 2009.05 doesn't set the PATH environment variable. Qt cannot find the MingGW tools.
 
Here's a bug: http://bugreports.qt.nokia.com/browse/QTCREATORBUG-517
 
right-click My Computer->Properties->Advanced->Environment Variables
in the upper box, if Path doesn't exist, add Path and set it to:
c:\qt\2009.05\mingw\bin;C:\Qt\2009.05\qt\bin

Or, if Path exists, double-click on it, append a semicolon, then append that string. Also, note your installation. If you install Qt after then next release, it may install in the "2010.01" directory or something similar.

Build->Rebuild All now gives me a green bar under "Build"--Success.

Researching: best practices for sequential pages

Trying QWizard
Trying the State Machine Framework
For my applications, perhaps Model-View Programming