このウィンドウはかなり開いてバンド名を要求します。行編集ウィジェットの文字が変数に格納されるようにしました。問題は私はmain window.cppと呼ばれる別のファイルがあり、その変数をそのウィンドウのリストウィジェットに保存するようにします。今、私はリストウィジェットに物を表示する方法を知っていますが、ユーザーが入力を終えた後にテキストを取得する方法を理解できません。メインのwindow.cppファイルのバンド名varは空の文字列を取りますが、なぜか分かりますが、ユーザーが入力を終えた後にget呼び出しをトリガーする方法はあります。 get関数のようにクラス内の何かを制限する必要がありますか?私はたくさんの実験をしてコールバックを見ましたが、信号とスロットだけを使用できます。 Iveが試したすべての文字列は空の文字列を返すだけですが、ユーザーが入力を完了したらテキストが必要です。ここでは名前のダイアログウィンドウがボタンをメンバー変数が別のファイルで変更された後に初期化されたオブジェクトの一部である関数を呼び出す
#include "addbutton.h"
#include "ui_addbutton.h"
AddButton::AddButton(QWidget *parent) :
QDialog(parent),
ui(new Ui::AddButton)
{
ui->setupUi(this);
connect(ui->cancel,SIGNAL(released()),this,SLOT(close()));
//Get Text when user presses enter
connect(ui->lineEdit, SIGNAL(editingFinished()),this,SLOT(setBandName()));
}
void AddButton::setBandName(){
bandname = ui->lineEdit->text();
}
void AddButton::updateState(){
pbandname = bandname;
}
QString AddButton::getBandName(){
return bandname;
}
AddButton::~AddButton()
{
delete ui;
}
を追加しているここで私は、私はあなたのポストを理解していない主なwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addbutton.h"
#include "bandinfo.h"
#include "QDebug"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mediaplayer = new Player;
connect(ui->pushbutton_addBand,SIGNAL(pressed()),this,SLOT(addBand()));
}
void MainWindow::addBand(){
BandInfo band;
AddButton *addband_window = new AddButton;
QString bandname;
addband_window->show();
bandname = addband_window->pbandname;
qDebug() << bandname;
}
MainWindow::~MainWindow()
{
delete ui;
}
感謝の男が今、私はこれについて考える別の方法を持って実際に使ったことがない更新は前に発します。しかし何らかの理由でシグナルとスロットは、使用されている関数の引数がないときには完全に機能します。私はそれに文字列の引数を置くとすぐに、そのような信号は何もヒントを言って信号を見つけることができません? – jamiroquai93
男は文法が間違っていた – jamiroquai93