Hi all
How can we make connections manually using Signals and Slots.
Thanx & Regards
merry
Hi all
How can we make connections manually using Signals and Slots.
Thanx & Regards
merry
Hello merry,
You can use thse functions of QObject class
Qt Code:
To copy to clipboard, switch view to plain text mode
To disconnect the signals and slots
Qt Code:
To copy to clipboard, switch view to plain text mode
You can take this example..
Qt Code:
...... QWidget w; a.setMainWidget(&w); ..........To copy to clipboard, switch view to plain text mode
The code i have written for Qt 3.3.3 and is same to Qt 4 also..
This is just to use the signals and slots already availiable.. To create custom slots and signals we have a procedure.
Regards,
merry (22nd February 2007)
Can you be a little more specific about what exactly you want to do?
Signals can be connected to slots using connect...
Qt Code:
connect( aButton, SIGNAL(clicked()), SLOT(myUsefulSlot()) );To copy to clipboard, switch view to plain text mode
In that example (from the docs) aButton is the object emitting the signal, clicked() is the name of the signal we are interested in, and myUsefulSignal() is the slot in our program we want it connected to.
You define slots in your header with the slot keyword:
Qt Code:
public slots: void myUsefulSlot();To copy to clipboard, switch view to plain text mode
Hope that helps.
merry (22nd February 2007)
Thanks for the reply
I am sending you the code with this code a treestructure/listview of files & folders is Created and also both files and folders are represented by different different images.
Now what I want is that When I clicked on any of the item of the listview it can be replaced by some other image. For this I Use signals and slots but it wont works.It wont give any error but at click event nothing happens,
View this code and reply me with the solution :
#include <qfiledialog.h>
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qstringlist.h>
#include<qmessagebox.h>
#include <qpixmap.h>
#include <qdir.h>
#include <qstringlist.h>
void Form1::fileOpen()
{
QListViewItem* root=new QListViewItem(listView);
m_source = QFileDialog::getExistingDirectory(
"/home/",
this,
"get existing directory",
"Choose a directory",
TRUE );
root->setText(0,m_source );
CreateDirTree(root,m_source);
}
void Form1::CreateDirTree(QListViewItem *item,QString path )
{
QDir dir(path);
const QFileInfoList * dirs=dir.entryInfoList();
{
if(dirs)
{
QFileInfoListIterator it(*dirs);
QFileInfo * fileInfo;
while(fileInfo=it.current())
{
++it;
if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
;
else if (fileInfo->isDir())
{
QString FilePath;
FilePath =path +"/"+ fileInfo->fileName();
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp->setPixmap(0,QPixmap("/root/qt/Tree/images/image1.png"));
CreateDirTree(m_temp,FilePath);
}
else
{
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp->setPixmap(0,QPixmap("/root/qt/Tree/images/pic1.png"));
}
}
}
}
connect(listView,SIGNAL(clicked(QListViewItem*)),t his,SLOT(reverse_images(QlistViewItem*)));
}
void Form1::reverse_images(QListViewItem* item)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/pic2.png"));
}
Thanx
merry
Does the declaration of Form1 have the required Q_OBJECT macro? Is reverse_images() declared as a slot? What does the connect statement return?
Please
- use the code tags to make the code readable
- post only relevant parts of the code
J-P Nurmi
Bookmarks