How to make QT make works on Snow Leopard

The title is quite award. Hehe. A couple of days ago, I planned to use QT to build some stuff. But I found it counld not find “make” cmd on my snow leopard. I searched a lot; but only found Qs, no As. Some suggested to install XCode (which gives your OS “make”). But I have already installed the latest Xcode.  How come?

At last, I re-installed Xcode. And it works now!

I notice that there wasn’t “make” cmd in my /usr/bin/ path, but one in /Developer/usr/bin/. So I even tried to add a ~/.bash_profile with “export PATH=$PATH:/Developer/usr/bin/” to use make in Terminal. But QT Creator still didn’t work. After I re-installed XCode from the Snow Leopard Disc. I got “make” back inside /usr/bin/.

Tags:

Comments(0)

Handle file drop in QT

File drop is an easy-to-use feature for users, as users can directly drag-and-drop a file from file browser onto your application. People may think it is difficult to implement. But actually, it is rather easy. Here is a fast way to start.

The main idea is to handle these two events, QDropEvent and QDragEnterEvent. The following shows how to handle them in your app.

First, add the following code to the class declaration in a header file,

protected:
    void dropEvent(QDropEvent *event);
    void dragEnterEvent(QDragEnterEvent *event);

Then add the implementation to the cpp file,

void CLASS::dragEnterEvent(QDragEnterEvent *event)
{
  if (event && event->mimeData()) {
    const QMimeData* md = event->mimeData();
    if (md->hasUrls())
        event->acceptProposedAction();
  }
}

and

void CLASS::dropEvent(QDropEvent *event)
{
    const QMimeData *data = event->mimeData();
    if(data->hasUrls())
      foreach(QUrl url, data->urls()) {
        QFileInfo info(url.toLocalFile());
            if(info.exists() && info.isFile())
          ///// do something with url.tolocalFile()
      }
}

One more thing, add the following code in the constructor of the class to enable the widget to accept the events.

setAcceptDrops(true);

That’s all!

Tags:

Comments(0)

how to use cout, cin, cerr in QT

Include

#include <QTextStream>
#include <stdio.h>

Create these instances globally

QTextStream cin(stdin, QIODevice::ReadOnly);
QTextStream cout(stdout, QIODevice::WriteOnly);
QTextStream cerr(stderr, QIODevice::WriteOnly);

Then you can use

cout<<QString("bla bla")<<endl

as you wish.

refer: http://lists.trolltech.com/qt4-preview-feedback/2005-03/thread00012-0.html

Tags:

Comments(0)

How to use OpenCV in QT under ubuntu

Install OpenCV with Synaptic Package Manager
Add one line in QT project file (*.pro)

LIBS += -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux

Then, include OpenCV header file in your source code.
Do whatever you like in your source file.
Compile.

Note: This post is incomplete so far and subject to change.

Tags: , ,

Comments(0)