1 Attachment(s)
connect a qpushbutton a slot
I am creating a text editor. I create 2 QPushButton one called Abrir and a Guardar, as you do for that clicking these button do what it say the slot?
void on_menuGuardar_triggered();
void on_menuAbrir_triggered();
and another question. in most of the programs in the Help menu, is an option called About. the windows is a QDialog or QMessageBox?
Re: connect a qpushbutton a slot
Quote:
Originally Posted by
Lycus HackerEmo
I am creating a text editor. I create 2 QPushButton one called Abrir and a Guardar, as you do for that clicking these button do what it say the slot?
Could you rephrase your question?
Quote:
and another question. in most of the programs in the Help menu, is an option called About. the windows is a QDialog or QMessageBox?
QMessageBox is also a QDialog, so...
Re: connect a qpushbutton a slot
Slot for pushbutton:
Code:
connect(menuGuardar, SIGNAL(clicked()),this, SLOT(on_menuGuardar_triggered()));
and about box is pretty much the same
Code:
void myProg::on_about_clicked()
{
msgBox.setWindowTitle("My About");
msgBox.setText("About my program");
msgBox.exec();
}
Re: connect a qpushbutton a slot
Quote:
Could you rephrase your question?
in the file *.ui add 2 buttons i wanted to do was connect it to the slot.
What i did was:
Code:
connect(ui->botonAbrir, SIGNAL(clicked()),this, SLOT(on_menuAbrir_triggered()));
connect(ui->botonGuardar, SIGNAL(clicked()),this, SLOT(on_menuGuardar_triggered()));
and on the About menu. was how to create this window? and how you create this link on the website?
http://img291.imageshack.us/img291/8...ntnea3x.th.png
Re: connect a qpushbutton a slot
Quote:
Originally Posted by
Lycus HackerEmo
and on the About menu. was how to create this window? and how you create this link on the website?
QVBoxLayout, QTabWidget, QLabel, QPushbutton. A QLabel can display links. Just set html as a text.
Re: connect a qpushbutton a slot
Quote:
Originally Posted by
Lycus HackerEmo
in the file *.ui add 2 buttons i wanted to do was connect it to the slot.
What i did was:
Code:
connect(ui->botonAbrir, SIGNAL(clicked()),this, SLOT(on_menuAbrir_triggered()));
connect(ui->botonGuardar, SIGNAL(clicked()),this, SLOT(on_menuGuardar_triggered()));
You shouldn't be doing it like this. The on_objectname_signalname() naming convention says the slot will be executed upon a "signalname" signal from "objectname" object. So either change the name to something meaningful and leave the connect statements as they are or get rid of the connect statements and change slot names so that they have "clicked" instead of "triggered" in their names.
Quote:
and on the About menu. was how to create this window? and how you create this link on the website?
Take a look at QMessageBox::about(). You can pass rich text (including links) there.
Re: connect a qpushbutton a slot
Quote:
Originally Posted by
wysota
You shouldn't be doing it like this. The on_objectname_signalname() naming convention says the slot will be executed upon a "signalname" signal from "objectname" object. So either change the name to something meaningful and leave the connect statements as they are or get rid of the connect statements and change slot names so that they have "clicked" instead of "triggered" in their names.
:) I thought the same way but then I saw that there is also an action named menuAbrir for which the slot is for. So the button is only additional. So the decission is to make all by hand or let Qt do at least one connection...
1 Attachment(s)
Re: connect a qpushbutton a slot
Quote:
You shouldn't be doing it like this. The on_objectname_signalname() naming convention says the slot will be executed upon a "signalname" signal from "objectname" object. So either change the name to something meaningful and leave the connect statements as they are or get rid of the connect statements and change slot names so that they have "clicked" instead of "triggered" in their names.
the signalname "triggered" only used in the menuBar and not be used in QPushButton?
have an example of what i should do?
I delete the "triggered" and change it to the "clicked", but does not work the menuAbrir and the menuGuardar.
Code:
connect(ui->botonAbrir, SIGNAL(clicked()),this, SLOT(on_menuAbrir_clicked()));
connect(ui->botonGuardar, SIGNAL(clicked()),this, SLOT(on_menuGuardar_clicked()));
connect(ui->menuAbrir, SIGNAL(clicked()),this, SLOT(on_menuAbrir_clicked()));
connect(ui->menuGuardar, SIGNAL(clicked()),this, SLOT(on_menuGuardar_clicked()));
Re: connect a qpushbutton a slot
menuArir and menuGuardar don't have a "clicked()" signal. Use triggered() for these.
Re: connect a qpushbutton a slot
I would really suggest to change the slot names to something meaningful and issue connect statements for both the buttons and the actions. Or better yet make your buttons tool buttons and add the actions you created to them. Then you won't have to double the connect statements.
Code:
button->addAction(act);
connect(act, SIGNAL(triggered()), this, SLOT(doSomethingUseful()));
1 Attachment(s)
Re: connect a qpushbutton a slot
and it's ok like this?
and mark error:
Code:
‘class
QAction’ has no member named ‘addAction’
Re: connect a qpushbutton a slot
Quote:
Originally Posted by
Lycus HackerEmo
Code:
‘class QAction’ has no member named ‘addAction’
Which is correct. Note that wysota used addAction method of QToolButton.
1 Attachment(s)
Re: connect a qpushbutton a slot
forgiveness for late reply, was busy with affairs of the school
and happy to have 2 weeks of easter holiday. xD
okay this program?
there is an error here? not working wants.
Code:
void TextEditor::acerca_de()
{
QMessageBox::about(this, tr
("Acerca de: TextEditor"), tr
("Este Programa fue creado por:\n\n" "<h3>Lycus HackerEmo</h3>\n\n"
"<a href="http://tuxmaya.wordpress.com">TuxMaya</a> "));
}
Re: connect a qpushbutton a slot
The code you pasted is syntactically incorrect. Even the forum highlighting shows that...