thanks for the tip, what do I write to present it?
thanks for the tip, what do I write to present it?
Something like...
mainwindow.h:
Qt Code:
#include <QtGui/QMainWindow> class QLineEdit; class QListWidget; { Q_OBJECT public: ~MainWindow(); protected slots: void addItemToList(); private: QLineEdit *m_edit; QListWidget *m_list; };To copy to clipboard, switch view to plain text mode
mainwindow.cpp:
Qt Code:
#include <QListWidget> #include <QLineEdit> #include <QVBoxLayout> #include "mainwindow.h" { layout->addWidget(m_list); layout->addWidget(m_edit); widget->setLayout(layout); setCentralWidget(widget); this, SLOT(addItemToList())); } MainWindow::~MainWindow() { } void MainWindow::addItemToList() { m_list->addItem(m_edit->text()); }To copy to clipboard, switch view to plain text mode
Last edited by helloworld; 1st April 2011 at 22:05.
omg that looks extremely complicated...
The thing is today is the first time I've ever opened Qt so I don't know squat...
I have this console based app I've written in visual studio that I would like to "connect" to the most basic gui in the easiest way possible and I've heard that qt is the way.
could anyone here give me some pointers?
Ok so I changed to QlistWidget and now I would like to make a function that checks my array (Test**test) and converts all std::strings to QStrings.
now I have no idea if this is even remotely correct but at least I tried something.Qt Code:
void Diet::toQString()const { //have an int this->kcal //and have three doubles this->protein, this->carb, this->lipid }To copy to clipboard, switch view to plain text mode
what I want this function to do is when I call it in listWidget it should present the info from the array from a certain slot.
Why don't you use QString from begin to end?
Anyway QString has some static functions like fromStdString you can use to create QString from std::string.
Also QString has ways to construct QStrings from int, check the QString documentation.
what do you mean by from beginning to end?
why I have std::string?
I mean to use QString instead of std::string all over the place (so that you don't need to convert strings)
Yeah I could do that, but then I have to change every single std::string to a QString and I'm almost sure that something will f*** up in the process.
You think thats the easiest way? easier than only to have a function that converts all strings to QStrings?
Well it is easier with conversion, but conversion means a copy of the string and if you have a lot of strings, and that lot increases, at some point that conversion might not be acceptable any more.
But if your number of conversions is low the performance penalty is also low.
//but for a new project you can use QString from the beginning and see that QString has many more features than std::string, so it may be easier to use.
ok, thanks for the tip.
What do you think about the function I posted above? Is that conversion working? and what can I write inside that function if I want all the data to be presented in a window.
I mean if I wanted to do that in VS I would only write cout but what about now?
You can still use cout to print QString to console with the help of qPrintable or you can use qstringName.toLocal8Bit().constData();
Or you can use qDebug()
But if I dont want to print it in the console? I want it to be printed out in the QListWidget.
Bookmarks