How to create custom slot in Qt Designer 4.1?
I am using the Qt 3 Designer manual to do my first Qt program because Qt 4 manual does not have such a Quick Start. The Qt 3 manual tells me to
* Select calculatePushButton for the Sender, clicked() for the Signal, and ConversionForm for the Receiver.
* Click Edit Slots to invoke the Edit Functions dialog. Click New Function. Type over the Function name with the name of our new function: convert(), then click OK.
* Select convert() from the Slot combobox to complete our connection.
But I do not see any "Edit Slots" in the Qt 4 signal/slot editor. Where do I add this convert() slot?
Thanks.
Re: How to create custom slot in Qt Designer 4.1?
No Way.
You cant Create custom slots like the one in Qt-3 ( using the designer ). When U subclass then u can add the custom slots yourself thereby eliminating the virtual funtions.
Hope you know that if u have a widget with signal - signal( param ). Then
a slot like on_widget_signal( param ) will connect the widget's signal to the slot
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by sunil.thaha
No Way. You cant Create custom slots like the one in Qt-3 ( using the designer ).
Ouch. I am totally new to Qt and C++ programming. (I knew a little C, but that was a long time ago. Isn't Qt 4 so friendly to start learning Qt?) I have submitted a bug to Trolltech asking them to give me us a Quick Start guide to Designer in Qt 4, but till then how do I learn Qt?
Re: How to create custom slot in Qt Designer 4.1?
So U r a newbie ..
Welcome to the Team!
I hope you have installed the Qt. assistant ( the help ) if so
Click the Qt Reference Documentation Section . ( Only Click )
Nowclick the How to learn Qt (link)
Enjoy learning Qt.
If you are new to C++. Please find time to learn C++. The Tutorial section above gives links. and you can also use Google Ofcourse.
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by sunil.thaha
Welcome to the Team!
Thanks.
Quote:
I hope you have installed the Qt. assistant
Yes of course I have. My problem is that I am trying to learn Qt and C++ at the same time as doing a new project for doing some astronomical calculations. That was how I learnt Visual Basic many years ago, while doing a custom accounts maintenance software for my father.
So I hope, with the help of the people here, I can learn Qt and C++ fairly well.
So can you please tell me whether the "portable C" code from the Swiss Ephemeris Code (1.2 MB) is implementable as is or as a library in Qt/C++?
Re: How to create custom slot in Qt Designer 4.1?
It is easy to learn qt and c++ in 15 days. I am saying so, because I had done it!!
The designer tutorial would be ulitmate helpful in this regard !
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by vkhaitan
It is easy to learn qt and c++ in 15 days. I am saying so, because I had done it!! The designer tutorial would be ulitmate helpful in this regard !
It is good to hear that. But please tell: what programming languages were you previously in knowledge of?
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by jamadagni
Ouch. I am totally new to Qt and C++ programming. (I knew a little C, but that was a long time ago. Isn't Qt 4 so friendly to start learning Qt?) I have submitted a bug to Trolltech asking them to give me us a Quick Start guide to Designer in Qt 4, but till then how do I learn Qt?
For learning Qt, there is a book called C++ GUI Programming with Qt 3, by J Blanchette & M Summerfield (Prentice Hall, 2004). It teaches all major aspects of Qt including the table and network modules. This might be a better step for a beginner than rushing straight into Qt 4 which so far is not well-documented other than for the reference documentation on the Trolltech website.
QtD4 is in my opinion a poor cousin for the Qt3 version, although some of its deficiencies have been made-up for in the 4.1 version - for example, there is a menu editor as there was in v3 and also an action editor. I still haven't found a way of adding actions to toolbars, though. And using Designer widgets in programs is nowhere near as simple as it was in Qt 3. For my project I'm using Qt 4.1 as by the time it's ready for use I suspect Qt and KDE 3 will both be obsolete, but Qt 3 right now is not obsolete and there may well be a greater body of experience out there in Qt 3 than Qt 4.
Re: How to create custom slot in Qt Designer 4.1?
You can add actions to toolbars by first creating an action in the action editor, and then drag them onto the toolbar of your choice. Unfortunately there is no way to drag widgets like spinners onto toolbars yet.
Regarding the Qt 3 book, it should be mentioned that it can be downloaded for free in PDF format here:
http://doc.trolltech.com/4.1/how-to-learn-qt.html
Re: How to create custom slot in Qt Designer 4.1?
Unfortunately after going through the Qt 4 docs many times haven't yet managed to add a custom slot.
The project uses:
main.cpp
simpleform.h
simpleform.cpp
What I am trying to do is include the .h file in simpleform.cpp and implement the custom slot in the .cpp file so just in case the form is changed I don't loose my changes because of uic.
If I copy and paste various examples, it seems to work. But not when designing my own form.
I use the CodeBlocks IDE (Just in case this could mean something)
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by cioannou
What I am trying to do is include the .h file in simpleform.cpp and implement the custom slot in the .cpp file so just in case the form is changed I don't loose my changes because of uic.
Have you read this (personally I prefer the single inheritance approach)?
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by cioannou
Unfortunately after going through the Qt 4 docs many times haven't yet managed to add a custom slot.
The bottom line is, you cannot write slots in Qt 4 Designer. That functionality has been taken out, and the .ui.h file system abolished, in Qt 4. Qt4D does have a signal/slot editor, but that only applies to connecting existing signals to existing slots.
To use your forms in programs, you need to follow the instructions in the Qt Designer Manual, specifically the section towards the bottom headed "Using Forms and Components".
To see an example of what the manual calls "The Single Inheritance Approach", you might like to look at the source code to my in-process app, to be found at its Sourceforge CVS repository: http://cvs.sourceforge.net/viewcvs.p...in/catkin-qtm/. You need to look at both catkin.h and catkin.cc, and note the use of the Ui namespace and the object which is used to set up the user-interface of another object. Thus, widgets and other objects coming from Qt Designer are clearly marked in the catkin.cc source code.
For the direct approach, two examples can be found in the catkin.cc file at the same repository, in the about() and getPreferences() methods.
Hope this helps.
Matt Smith
Re: How to create custom slot in Qt Designer 4.1?
Thanks a lot for the info,
have already tried all methods mentioned in the docs, but they all failed, so I will check your example.
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by jamadagni
Ouch. I am totally new to Qt and C++ programming. (I knew a little C, but that was a long time ago. Isn't Qt 4 so friendly to start learning Qt?) I have submitted a bug to Trolltech asking them to give me us a Quick Start guide to Designer in Qt 4, but till then how do I learn Qt?
Like you are trying to do, I learned both QT4 and C++ at the same time.
It's not that hard.
For example, you declare a slot in your app.h file:
Code:
private slots:
...
void searchAll();
Then you put a connection in the constructor of your app class, in app.cpp:
Code:
connect(ui.btnSearch, SIGNAL(clicked()), this, SLOT(searchAll()));
and, you put the function in app.cpp, outside the constuctor:
Code:
void app::searchAll() {
// user enters value to search for in search text box
....
Re: How to create custom slot in Qt Designer 4.1?
Quote:
For example, you declare a slot in your app.h file:
Code:
private slots:
...
void searchAll();
That's exactly what I am trying to avoid.
If I change the app.h that is generated by the designer and afterwards add some new widgets to my dialog, all my private slots will be lost.
Am I missing something?
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by cioannou
If I change the app.h that is generated by the designer and afterwards add some new widgets to my dialog, all my private slots will be lost.
Don't touch those files and instead create another class. You can find the exact instructions here, but in short you need something like this:
Code:
#include <QDialog>
#include "ui_somedialog.h" // this file was made from somedialog.ui by uic
{
Q_OBJECT
public:
private slots:
void searchAll();
private:
Ui::SomeDialog _ui;
};
// .cpp file:
{
_ui.setupUi( this );
// ...
}
void SomeDialog::searchAll()
{
// ...
}
1 Attachment(s)
Re: How to create custom slot in Qt Designer 4.1?
OK, here are some excepts of my Homestead app that do what I believe you want to do. This code throws up a dialog which contains a list of wholenames selected from a SQL select of type form "LIKE partialname%". Clicking on the proprty_id column and/or the ssn column selects that property or that individual. Clicking the OK or Cancel button closes the dialog.
Here is the wholenamedlg.h header file:
Code:
#ifndef WHOLENAMEDLG_H
#define WHOLENAMEDLG_H
.... snip includes ..........
#include "ui_wholenamedlg.h"
class wholenamedlg
: public QDialog{
Q_OBJECT
public:
private:
Ui::wholeNameDlgUI wnui;
private slots:
};
#endif
"wholeNameDlgUI" is the name given to the dialog during the Designer session.
Here is the wholenamedlg.cpp file which displays the dialog grid:
Code:
/*
Program: wholenamedlg.cpp
Description: A dialog class for picking an SSN and/or a name out of
a query created by the SQL LIKE % syntax.
Author: Jerry L Kreps
Date: 11/10/05 - ff
*/
#include "wholenamedlg.h"
... snip includes ......
{
wnui.setupUi(this);
partName.prepend("'");
partName.append("'");
QString queryStr
= "SELECT proprty_id,ssn,wholename,sssn,sname,city,address FROM persinfo_";
queryStr.append(strYear);
if (strSpouseFlag == "F") {
queryStr.append(" WHERE wholename LIKE ");
queryStr.append(partName);
queryStr.append(" ORDER BY wholename");
} else {
queryStr.append(" WHERE sname LIKE ");
queryStr.append(partName);
queryStr.append(" ORDER BY sname");
}
viewModel->setHeaderData(0, Qt::Horizontal, "ID");
viewModel->setHeaderData(1, Qt::Horizontal, "SSN");
viewModel->setHeaderData(2, Qt::Horizontal, "WholeName");
viewModel->setHeaderData(3, Qt::Horizontal, "SSSN");
viewModel->setHeaderData(4, Qt::Horizontal, "SName");
viewModel->setHeaderData(5, Qt::Horizontal, "City");
viewModel->setHeaderData(6, Qt::Horizontal, "Address");
viewModel->setQuery(queryStr);
if (viewModel
->lastError
().
type() == QSqlError::NoError){ wnui.wholeNameView->setModel(viewModel);
if (viewModel->rowCount() > 0){
for (int i = 0; i < viewModel->rowCount(); ++i)
this->wnui.wholeNameView->verticalHeader()->resizeSection(i,20);
for (int i = 0; i < 7; ++i)
wnui.wholeNameView->resizeColumnToContents(i);
}
}
}
void wholenamedlg
::copyVALUES(const QModelIndex &QMI
) { QVariant value
= this
->wnui.
wholeNameView->model
()->data
(QMI,
0);
if (value.isValid()) {
if (QMI.column() == 0)
this->resultPropID = value.toString();
if (QMI.column() == 1)
this->resultSSN = value.toString();
}
}
"wholeNameView" is the name given in the Designer to the tableview grid containing the data being displayed.
Here is the main class for the homestead application. The segment shown displays that part of the searchALL() function which calls the wholenamedlg dialog.
Code:
/*
Program: homestead.cpp
Description: Homestead Application Program (HAP)
Author: Jerry L Kreps
Date: 11/1/2005
*/
#include "homestead.h"
#include "wholenamedlg.h"
...
// homestead constructor method
ui.setupUi(this); // draw the gui interface
this->Year65 = 1940; // set birth year for 65 year olds
this->dbYear = "2006";
...
connect(ui.btnSearch, SIGNAL(clicked()), this, SLOT(searchAll()));
...
...
} // end of the homestead constructor
void homestead::searchAll() {
// user enters value to search for in search text box
// and clicks the radio button indicating its data type
// then clicks the search button
bool foundProp = false;
bool foundPers = false;
QString seekWN
= "'";
// set up for possible wholename search requestString = "Searching for: ";
requestString.append(ui.leSearch->text()); // echo search request
if (ui.rbWholeName->isChecked()) {
QString partialName
= ui.
leSearch->text
().
trimmed();
if (partialName.contains('%')){
//select proprty_id,ssn,wholename,sssn,sname,city,address from persinfo_2006
//WHERE wholename LIKE 'MILLER/E%' ORDER BY wholename
wholenamedlg dlg(this, partialName, this->dbYear, "F");
if( dlg.
exec() == QDialog::Accepted ){ QString strSSN
= dlg.
resultSSN.
trimmed();
QString strPropID
= dlg.
resultPropID.
trimmed();
// was ssn returned from dialog ?
.....
..... snip lot's of code .....
.....
Here is what the dialog looks like in action:
Attachment 26
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by jacek
Don't touch those files and instead create another class. You can find the exact instructions
here, but in short you need something like this:
Code:
#include <QDialog>
#include "ui_somedialog.h" // this file was made from somedialog.ui by uic
{
Q_OBJECT
public:
private slots:
void searchAll();
etc. etc etc
}
Ok , it's obvious that I am stupid and noob at the same time (in c++ & qt), so I can't be more embarassed.:confused: :(
here is my code:
Code:
#include <qapplication.h>
#include "ui_bullshit.h"
{
Q_OBJECT
public:
private:
Ui::bullshit ui;
};
bullshit
::bullshit( QWidget *parent
){
ui.setupUi( this );
// ...
}
int main(int argc, char **argv)
{
Ui::bullshit _ui;
_ui.setupUi(window);
window->show();
return app.exec();
}
If i compile main.cpp it's ok , but linker gives me a nice error:
main.cpp undefined reference to `vtable for bullshit'
I should not paste the errors I get when I use a separate .h and .cpp for the class constructor and functions.
Re: How to create custom slot in Qt Designer 4.1?
Quote:
Originally Posted by cioannou
main.cpp undefined reference to `vtable for bullshit'
Add:
Code:
#include "main.moc"
at the end of main.cpp and run "qmake && make".
Re: How to create custom slot in Qt Designer 4.1?
Thanks a lot , it compiled && linked now, but still not working
Code:
#include <qapplication.h>
#include <qmessagebox.h>
#include "ui_bullshit.h"
class bullshit
: public QDialog,
private Ui
::bullshit {
Q_OBJECT
public:
// private:
// Ui::bullshit ui;
private slots:
void msgbox();
void on_helloButton_clicked();
};
{
setupUi(this);
connect(helloButton,SIGNAL(clicked()),this,SLOT(msgbox()));
}
void bullshit::msgbox()
{
QMessageBox::information(this,
"Application name",
"The factory default will be used instead.");
}
void bullshit::on_helloButton_clicked()
{
QMessageBox::information(this,
"Application name",
"The factory default will be used instead.");
}
Can you please explain why we included the .moc file?
Txs