send signal from QCombobox
QT:4.1.1
Hi everybody!
I am trying to call a function from my combobox but i was not able. I tryied: all signals but it not works.
It would be perfect if i click on my combobox and send a signal, or call my function...
Have somebody a idea how could i call my function by clicking my combobox for example.
My Combobox is per default empty. And my idea is that when you click the combobox a query will started and values should be added to this combobox
I tried this:
Code:
connect(ui.sprache_cb, SIGNAL( activated()), this, SLOT(selectSprache()));
connect(ui.sprache_cb, SIGNAL( clicked()), this, SLOT(selectSprache()));
connect(ui.sprache_cb, SIGNAL( highlighted()), this, SLOT(selectSprache()));
Have i a chance to solve it?
Re: send signal from QCombobox
Run the app from the command prompt and see if you get any warnings.
Re: send signal from QCombobox
Quote:
Originally Posted by raphaelf
QT:4.1.1
Hi everybody!
I am trying to call a function from my combobox but i was not able. I tryied: all signals but it not works.
It would be perfect if i click on my combobox and send a signal, or call my function...
Have somebody a idea how could i call my function by clicking my combobox for example.
My Combobox is per default empty. And my idea is that when you click the combobox a query will started and values should be added to this combobox
I tried this:
Code:
connect(ui.sprache_cb, SIGNAL( activated()), this, SLOT(selectSprache()));
connect(ui.sprache_cb, SIGNAL( clicked()), this, SLOT(selectSprache()));
connect(ui.sprache_cb, SIGNAL( highlighted()), this, SLOT(selectSprache()));
Have i a chance to solve it?
So presumably, you start with an empty combobox and you want to react to when the mouse is clicked on it and the combo "drops down"?
or did I misunderstand?
Re: send signal from QCombobox
Hi Chicken Blood!
Yes the combobox should be empty at the beginning..(After the first query started the combobox will not be empty)
And allways when i click my combobox i should see the newest values from the database.
I dont now wich signal exactly i should use, i just must be shure that on click or activated the combobox, a query should be startet to be sure that the combobox contains the newest values and should be able to choose one of them..
Re: send signal from QCombobox
Just idea...use event filter for catch event QEvent::Show for object yourCmb->listBox()
Re: send signal from QCombobox
activated and highlighted signals are emitted only when combo box contains items than can be activated or highlighted.
Try this:
Inherit QComboBox and override:
When the combo box receives focus for the first time (when it's empty), you could emit a signal stating it needs to be populated.
Re: send signal from QCombobox
Hi everybody,
Zlatko and Jpn, the both idea are nice..
Where could i find examples?I need more Information how to implement it..
Thanx
Re: send signal from QCombobox
Do try to create the successor from the QComboBox class. Such as:
Code:
{
Q_OBJECT
public:
ComboBoxModify
(QWidget * pParent
= 0)public slots:
void setCurrentIndex ( int index )
{
};
};
Re: send signal from QCombobox
Code:
// in header of your form
protected:
// in constructor your form
installEventFilter(yourCmb->listBox());
// then
{
if ( e
->type
() == QEvent::Show ) {
yourMethod();
return TRUE; // eat event
} else
{
// standard event processing
return FALSE;
}
}
Re: send signal from QCombobox
Hi Zlatko,
Thanks for your fast Support!
I get a error Message:
Code:
test.cpp:16: error: 'class QComboBox' has no member named 'listBox'
Could be that you mean another member?I think listbox was in Qt3 possible..
MAD MAX: Thanks for your example too, i have see just now(you reply in 120 seconds)..I will try all sendet examples ;)
Re: send signal from QCombobox
Yes qt4 hasnt..i think you must use comboboxes method view()
Re: send signal from QCombobox
Hi,
I get No Errors now...But if i click my ComboBox my Function "selectSprache()" will not be called, Can somebody see why?
Code:
#include "test.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QTextEdit>
#include <QStatusBar>
#include <QAbstractItemView>
#include <QEvent>
MainWindow::MainWindow()
{
ui.setupUi(this);
installEventFilter(ui.sprache_cb->view());
connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(verbinden()));
connect(ui.speichern_btn, SIGNAL(clicked()), this, SLOT(selectSprache()));
}
bool MainWindow::verbinden()
{
db.setHostName("pcpsr5");
db.setDatabaseName("DRIVER={SQL Server};SERVER=pcpsr5;DATABASE=inventar;UID=sa;PWD=");
db.setUserName("sa");
db.setPassword("");
if(!db.open())
{
QMessageBox::information(this,
"",db.
lastError().
text());
return false;
}
else
return true;
}
void MainWindow::selectSprache()
{
/*
QSqlQuery select (" select sprache from sprache_tbl");
while(select.next())
{
QString sprachen = select.value(0).toString();
ui.sprache_te->insertPlainText(sprachen + " ");
}
*/
}
{
if ( e
->type
() == QEvent::Show ) {
selectSprache();
return TRUE;
}
else
return FALSE;
}
Code:
#include "ui_mainwindow.h"
{
Q_OBJECT
public:
MainWindow();
public slots:
bool verbinden();
void selectSprache();
private:
Ui::MainWindow ui;
protected:
};
Re: send signal from QCombobox
Stop...its bad idea catch this event if listview is empty :o .
Has your combo is editable?
If no try use event filter for object combobox and something event alikeQEvent::MouseButtonPress
sorry for my thoughtlessness
Re: send signal from QCombobox
The way event filters are used is:
monitoredObj->installEventFilter(filterObj)
so in your case it would be:
ui.sprache_cb->installEventFilter(this)
If you want to populate your combo box due to a click, you might wanna consider changing QEvent::Show to some other event. Combo box receives the show event during the startup of the application..
Re: send signal from QCombobox
Quote:
Originally Posted by jpn
The way event filters are used is:
monitoredObj->installEventFilter(filterObj)
so in your case it would be:
ui.sprache_cb->installEventFilter(this)
If you want to populate your combo box due to a click, you might wanna consider changing QEvent::Show to some other event. Combo box receives the show event during the startup of the application..
he try catch Event::Show from comboboxes listview
Re: send signal from QCombobox
Quote:
Originally Posted by zlatko
he try catch Event::Show from comboboxes listview
Ok, then there is a problem that the list never gets shown as it's empty..
Edit: as you seem to have already noticed :) Nevermind...
Re: send signal from QCombobox
Hi Guys..
like that it works, but just if i dobleclick my combobox :(
Code:
#include "test.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QTextEdit>
#include <QStatusBar>
#include <QAbstractItemView>
#include <QEvent>
MainWindow::MainWindow()
{
ui.setupUi(this);
ui.sprache_cb->installEventFilter(this);
connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(verbinden()));
}
bool MainWindow::verbinden()
{
db.setHostName("pcpsr5");
db.setDatabaseName("DRIVER={SQL Server};SERVER=pcpsr5;DATABASE=inventar;UID=sa;PWD=");
db.setUserName("sa");
db.setPassword("");
if(!db.open())
{
QMessageBox::information(this,
"",db.
lastError().
text());
return false;
}
else
return true;
}
void MainWindow::selectSprache()
{
ui.sprache_cb->clear();
ui.sprache_cb->insertItem(0,"");
QSqlQuery select
(" select sprache from sprache_tbl");
while(select.next())
{
QString sprachen
= select.
value(0).
toString();
ui.sprache_cb->insertItem(1, sprachen);
}
}
{
if ( e
->type
() == QEvent::MouseButtonPress ) {
selectSprache();
return TRUE;
}
else
return FALSE;
}
Re: send signal from QCombobox
Re: send signal from QCombobox
Hi!
I get new values just if i click twice..and on release the small button right from the combobox stay active (like a toogle button) until a click again ;(
May be its not the right way to send a Signal from the ComboBox..
Re: send signal from QCombobox
Hi,
"QEvent::FocusIn" looks to work but i have a symptom..if i ordered my query the results are interchanged
combo: x,f,a
Query Analyzer: a,f,x
"select sprache from sprache_tbl order by sprache"
:confused: