I'm sorry if any of this isn't detailed enough or doesn't make sense, I was up until 5:30 this morning trying to get this working. I have tried using a string array, declaring my strings as QStrings, and converting my string to a QString. I have a C++ code that I will post at the end of my question that prints a random string from an array then asks if that is what is wanted and if so it will exit the loop and I want to incoperate that code into a QT application where a push button would run the code and print the result to a lineEdit (it doesn't necesarrily have to be a lineEdit just anything that would display text). I know that I have to get rid of the loop since it's a push button but I can't for the life of me figure out how to make it print the variable. Any help would be greatly appreciated and if I need to clarify anything please let me know, thanks.
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
string ans = "no";
string result;
int a;
string result;
string myarr[] = {"foo", "bar", "etc"};
do{
srand(time(0));
a = sizeof(myarr) / sizeof(myarr[0]);
result = myarr[rand() % a];
cout << result<<endl;
cout << "Will that work?";<<endl;
cin >> ans;
while(ans=="no");
cout << "Glad I could help."<<endl;
reurn 0;
}
soryy, I have tried
void MainWindow::on_pushButton_clicked()
{
string ans = "no";
string result;
int a;
string result;
string myarr[] = {"foo", "bar", "etc"};
srand(time(0));
a = sizeof(myarr) / sizeof(myarr[0]);
result = myarr[rand() % a];
ui->lineEdit->setText(result);
}
I have also tried declaring result as a QString instead of a string, and a post I found for converting string into QString but I don't recall the syntax for that.