Accessing value of lineEdit in .cpp file- [SOLVED]
-
Hi ogopa,
Do you use a form wit ui file? And is your class based on it?
In a previous post you said you got it working. That's why I assumed you did use an ui file.The code I showed you is an example on how you can do things, to learn the general principles. You can not just copy it in your code.
Try it out using a new project based on QWidget, choose QDialog in one of the next steps and try my suggestion to learn things.
Did you read the signal and slots link I gave you?
Here is some explanation:
TestFunc is an example slot compararable to your function. Using the connect you can use the value of the lineEdit in your function. -
[quote author="Eddy" date="1311879430"]Hi ogopa,
Do you use a form wit ui file? And is your class based on it?
In a previous post you said you got it working. That's why I assumed you did use an ui file.The code I showed you is an example on how you can do things, to learn the general principles. You can not just copy it in your code.
Try it out using a new project based on QWidget, choose QDialog in one of the next steps and try my suggestion to learn things.
Did you read the signal and slots link I gave you?
Here is some explanation:
TestFunc is an example slot compararable to your function. Using the connect you can use the value of the lineEdit in your function.[/quote]
Thanks for the help so far. So i've been reading the signals and slots link you sent me and I tried out a simple project with QDialog. I'm still trying to connect the lineEdit to another function, I can't seem to nail it :(. I named the test function write_loop again :p. Below is the cpp file and below that is the header file.
dialog.cpp
@#include "dialog.h"
#include "ui_dialog.h"
#include <QDialog>
#include <QDebug>
#include <iostream>
using namespace std;static double txt;
dialog::dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::dialog)
{
ui->setupUi(this);
connect(ui->lineEdit, SIGNAL(textChanged(QString)), this , SLOT(write_loop(QString)) );
}dialog::~dialog()
{
delete ui;
}void dialog::write_loop(QString str)
{
qDebug() << "teststring : " <<str;
}void dialog::on_pushButton_clicked()
{
txt = ui->lineEdit->text().toDouble();
cout<<txt;
}static int write_loop(QString)
{
txt = ui->lineEdit->text().toDouble();
cout<<"I have"<<txt;
}@dialog.h
@#ifndef DIALOG_H
#define DIALOG_H#include <QDialog>
#include <QDebug>namespace Ui {
class dialog;
}class dialog : public QDialog
{
Q_OBJECTpublic:
explicit dialog(QWidget *parent = 0);
~dialog();
public slots:
void write_loop(QString str);private slots:
void on_pushButton_clicked();private:
Ui::dialog *ui;
};#endif // DIALOG_H
@I also tried this, but it didn't work:
@static int write_loop(QString)
{
connect(ui->lineEdit, SIGNAL(textChanged(QString)), this , SLOT(write_loop(QString)) );
txt = ui->lineEdit->text().toDouble();
cout<<"I have"<<txt;
}
@ -
Do you know how to use Qt Creator? Do you know how to debug? Please read the Qt Creator manual if you don't. The purpose of this forum is not that we debug for you. You should be able to narrow down the problems yourself.
So your problem is merely about the static variable. Why do you want to use static? Using the signal slots you can have the value of the lineEdit where you want all the times.
If you keep only the function with the qDebug line in it then your program should work and you have a solution to your initial problem : using the vale of lineEdit in a function.
Hint : comment the others out and start from there. -
[quote author="Eddy" date="1311971610"]Do you know how to use Qt Creator? Do you know how to debug? Please read the Qt Creator manual if you don't. The purpose of this forum is not that we debug for you. You should be able to narrow down the problems yourself.
So your problem is merely about the static variable. Why do you want to use static? Using the signal slots you can have the value of the lineEdit where you want all the times.
If you keep only the function with the qDebug line in it then your program should work and you have a solution to your initial problem : using the vale of lineEdit in a function.
Hint : comment the others out and start from there.[/quote]Yayy, I got it, Thanks alot. I now have new errors. All of them are similar:
wave.cpp:(.text+0x7b3): undefined reference tosnd_pcm_hw_params_set_rate_resample' wave.cpp:(.text+0x7c6): undefined reference to
snd_strerror'
wave.cpp:(.text+0x7f6): undefined reference tosnd_pcm_hw_params_set_access' wave.cpp:(.text+0x809): undefined reference to
snd_strerror'
wave.cpp:(.text+0x83c): undefined reference to `snd_pcm_hw_params_set_format'its the same for all others from the alsa sound library. I have included alsa/asoundlib.h, so i'm confused as to why i am getting these errors. Could you please help me.
-
[quote author="mlong" date="1311975549"]Make sure you're linking the asound library, not just include its header files.
[/quote]Hi, I tried searching online for your suggestion as I am not sure how to do this, but I couldn't find anything that could help me. Would you please explain a little more? I'd really appreciate it.
-
[quote author="mlong" date="1312296267"]What does your .pro file look like?
[/quote]@#-------------------------------------------------
Project created by QtCreator 2011-07-26T15:57:33
#-------------------------------------------------
QT += core gui
TARGET = Wave
TEMPLATE = appSOURCES += main.cpp
wave.cppHEADERS += wave.h
FORMS += wave.ui@
-
It's not enough to simply include the <alsa/asoundlib.h> header in your code. You also have to tell the linker that you want to use the asound library. Use the LIBS variable in your .pro file to do so. I don't know for sure what the proper library name to use is (off the top of my head.) Probably want to use -Lasound or something like that.
There are a number of threads that discuss how to include libraries.