LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-24-2009, 08:21 AM   #1
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Rep: Reputation: 15
Qt noob needs help in making simple Qt application


I wish to write a small image resizing application (front-end to imageMagic's 'convert'), but I am total noob in Qt and linux dev tools. Not total noob though (senior Delphi and Adobe Flex/AS3 developer). I have basic knowledge of C++ and Python.

So I took Qt4 designer and designed my form, placed signals and slots, saved file, ... and that is about where my knowledge ends.
I tried to use KDevelop, but it is complex and create bunch of files, and I couldn't find where to import my UI or how to do it. Then i opened QDevelop which is simpler, could link my UI, but gave me bunch of errors as classnames was not the same as template. Tried to do something in it, but with no success.

So, my question is: is there anyone who can teach me how to make an application from an UI form? Since the application is fairly simple, I think it will not take too much time.
 
Old 11-24-2009, 10:18 AM   #2
Guitarist88
Member
 
Registered: Feb 2004
Location: Nz
Posts: 240

Rep: Reputation: 30
There are a lot of great books about using the Qt GUI toolkit. Coming on here asking for someone to do the work for you or tell you how to do everything, essentially, sounds like you have no initiative. Get one of the books... Also, Qt's own documentation is very helpful. There are many examples and tuturials you can work through.

http://doc.trolltech.com/4.3/tutorial.html

Last edited by Guitarist88; 11-24-2009 at 10:21 AM.
 
Old 11-24-2009, 10:38 AM   #3
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Can I suggest you use qt-creator?

KDevelop doesn't work on KDE4 and you really need to be developing KDE4 apps now.

Get the IDE from here:

http://qt.nokia.com/products/developer-tools

It has some very nice example projects.

It sounds like you've worked out how to place parts, the next thing, that is hard to get your head round at first, is signals and slots.

As a very simple example if you have placed a button and a label on your form, you can get the button to affect the label in the following way:

Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->rPushButton,SIGNAL(clicked()),this,SLOT(buttonPressed()));

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_rPushButton_clicked()
{

    ui->label->setText("Yo!");
    


}

Here I have used the qizard to create a new application and added a ui form called mainwindow. I called the pushbutton "rPushButton" and the label, er, "label".

The signal is clicked() and it's connecting to the slot on_rPushButton_clicked(). Hopefully that aprt is fairly intuitive.

My mainwindow.h file looks like this:

Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>


QT_BEGIN_NAMESPACE
class QPushButton;


namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
        QPushButton *ui_findButton;

private slots:
    void on_rPushButton_clicked();


};

#endif // MAINWINDOW_H
Most of it is done automatically by the IDE.

I really do like this new qt-creator. It's fast, not some horrible Java thing like Eclipse and looks really nice.

Good luck and come back and ask if you want more help. I found this hideously complex when I first had a go and would never have made it without help from a friend. I don't think you have no initiative if you've got as far as you have.

Last edited by DiBosco; 11-24-2009 at 10:40 AM.
 
Old 11-24-2009, 10:56 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
For a **simple** front-end, why not dialog ( or kdialog, and other variants) or zenity?

Good book including how to write GUIs: http://www.amazon.com/Beginning-Linu.../dp/1874416680
 
Old 11-25-2009, 04:19 AM   #5
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
Thank you all.
I was lost. Read few tutorials but they dont explain what I need.. just supposing that you know all the tools and "just do it'.
I will look into it. It is all confusing in the beginning.
@Guitarist88 And no, I didn't ask to be done instead of me (I hate that), just to give me guidelines to start. I have read bunch of tutorials and nowhere to find : "you made your UI, now start working with it by opening "THIS_TOOL and do THIS and THAT"
 
Old 11-25-2009, 04:57 AM   #6
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
@DiBosco, qt-creator is so awesome!!!
I think I will manage to do something in it.

Thank you!
 
Old 11-25-2009, 08:06 AM   #7
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
@DiBosco

Yes yes yes! I figured it out, thanks to your example.
 
Old 11-25-2009, 08:09 AM   #8
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Quote:
Originally Posted by beli0135 View Post
@DiBosco

Yes yes yes! I figured it out, thanks to your example.
Excellent.

This is a useful page:

http://doc.trolltech.com/4.3/classes.html
 
Old 11-26-2009, 06:20 AM   #9
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
Believe it or not, my program is almost ready... basic version
I will ask you for some things, if I may?
 
Old 11-26-2009, 06:54 AM   #10
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Quote:
Originally Posted by beli0135 View Post
Believe it or not, my program is almost ready... basic version
I will ask you for some things, if I may?
Sure!
 
Old 11-27-2009, 04:12 AM   #11
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
I'd like to keep some settings in text file.
For example if I have:
#
SOURCE=/home/myuser/pictures
DESTINATION=/home/myuser/pictures/resized

How do I read and write it easily? In Lazarus/Delphi, StringList has property "Values", so I can do like this:
MyStringList.values['SOURCE'] = whatever_to_Write
whatever_to_read = MyStringList.values['SOURCE'];
 
Old 11-27-2009, 04:50 AM   #12
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Here's an example of (I hope) what you're asking to do:

Code:
void ordernumber::set_initials(QString s)
{

	bool i;

	QString		PathName(QDir::homeDirPath ());
	QString		FullPath;		

	FullPath = (PathName + "/.kde/ordernumber");
	QDir  d1(FullPath);
	if (!d1.exists() )
		{
		d1.mkdir(FullPath);
		}

	QFile f1(FullPath+"/profile.ini");
// Create a DataStream object

	i = f1.open( IO_WriteOnly );
	QTextStream		SaveStream( &f1 );
	SaveStream << s;
	f1.close();


	
}
Hopefully that's easy enough to follow. Making the path to where I want the file first, then setting up the file name, then creating the file, opening it, writing this "stream" to it and finally closing the file.

Bear in mind this is Qt3, so it might be slightly different now. Checkout QTextStream in that link I posted above for more details on what it can do. It's very cool for opening files and quickly parsing them a line at a time. Although in some ways Qt is harder to get to grips with than Delphi at first, I think it's probably more powerful once you get into it.

This snippet from a program I wrote to look through dynamically create files when a USB device is plugged in might give you a bit more of an idea. :~)

Code:
if ((hpVariables[Offset].VarType=="enum") || (hpVariables[Offset].VarType=="bitmask"))
		{
		if (hpVariables[Offset].VarType=="enum")
			FileName = TypeDirectory + "/enum_val";
		else if (hpVariables[Offset].VarType=="bitmask")
			FileName = TypeDirectory + "/bit_val";
		QFile f2(FileName);
		i = f2.open( IO_ReadOnly );
		QTextStream	OpenStream( &f2 );
		j=0;
		while (!f2.atEnd())
			{			
			s=OpenStream.readLine();
			hpVariables[Offset].ParamNames[j] = s;
			++j;
			}
		hpVariables[Offset].ParamQuantity = j;
		f2.close();

Last edited by DiBosco; 11-27-2009 at 04:51 AM.
 
Old 11-28-2009, 10:26 AM   #13
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
O thanks!

Seems that Qt stores variables just as delphi does.
I will use your example as a basis for my settings read-write.
 
Old 11-28-2009, 02:06 PM   #14
beli0135
Member
 
Registered: Jul 2008
Posts: 39

Original Poster
Rep: Reputation: 15
Actually, I find class QSettings which is a real nice way to store your settings. Actually you dont think of anything, and let hard part to Qt...

Usage:

Code:
void MainWindow::writeSettings()
 {
     QSettings settings("Moose Soft", "Clipper");

     settings.beginGroup("MainWindow");
     settings.setValue("size", size());
     settings.setValue("pos", pos());
     settings.endGroup();
 }

 void MainWindow::readSettings()
 {
     QSettings settings("Moose Soft", "Clipper");

     settings.beginGroup("MainWindow");
     resize(settings.value("size", QSize(400, 400)).toSize());
     move(settings.value("pos", QPoint(200, 200)).toPoint());
     settings.endGroup();
 }
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Xfce! A few simple questions for a super-noob Taigrr Linux - Software 3 04-04-2006 05:16 PM
Simple linux noob firewall question tarbash7 Linux - Security 2 02-04-2006 08:13 PM
simple noob question (samba) Slimster Ubuntu 4 10-29-2005 07:16 AM
simple noob question (samba) Slimster Debian 3 10-03-2005 09:53 AM
Linux Noob writing simple application that needs to query SQLServer radikaled Linux - Newbie 1 01-18-2005 11:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration