Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9050787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:44:31+00:00 2026-06-16T12:44:31+00:00

I am driving myself crazy trying use variables in another function in the same

  • 0

I am driving myself crazy trying use variables in another function in the same file:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)

{

    QLineEdit * street1BetSize = new QLineEdit("0"); // want to use these QLineEdit's
    QLineEdit * street2BetSize = new QLineEdit("0");
    QLineEdit * street3BetSize = new QLineEdit("0");
    QLineEdit * street4BetSize = new QLineEdit("0");
    QLineEdit * street5BetSize = new QLineEdit("0");

}

want to use thos variables here:

void MainWindow::runButtonClicked()
{
    QVector<card> vDealt = cardDeck.deal_rand_cards(vDeck,3);
    //qDebug()<<vStreetBets[0];

    streetBetsList << street1BetSize << street2BetSize << street3BetSize << street4BetSize << street5BetSize;
    QVector<int> vStreetBets;
    for(int i=0;i<5;i++)
    {
         vStreetBets.append(streetBetsList[i]->text().toInt());
         qDebug()<<"street bet: "<<vStreetBets[i];
    }
}

As it is here, I am getting

warning: C4189:
‘street5BetSize’ : local variable is initialized but not referenced

and

error: C2065: 'street5BetSize' : undeclared identifier

for each one.

I tried adding extern QLineEdit * street1BetSize; to mainwindow.h, but this gives me an “unresolved external” error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:44:32+00:00Added an answer on June 16, 2026 at 12:44 pm

    If you are going to have five QLineEdits for each MainWindow, then you want them to be members of your class. Just add them to your class definition:

    class MainWindow
    {
      // ...
     private:
      // ...
      QLineEdit* street1BetSize;
      QLineEdit* street2BetSize;
      QLineEdit* street3BetSize;
      QLineEdit* street4BetSize;
      QLineEdit* street5BetSize;
    }
    

    Now, each MainWindow object will have 5 pointers to QLineEdit. These make up part of the state of that object and can be accessed by any of its member functions. Now change your constructor to the following, so that you don’t redefine the names:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        street1BetSize = new QLineEdit("0");
        street2BetSize = new QLineEdit("0");
        street3BetSize = new QLineEdit("0");
        street4BetSize = new QLineEdit("0");
        street5BetSize = new QLineEdit("0");
    }
    

    In fact, you’d be better off using the member initialization list, as you have done for QMainWindow and ui:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent), ui(new Ui::MainWindow),
        street1BetSize(new QLineEdit("0")), street2BetSize(new QLineEdit("0")),
        street3BetSize(new QLineEdit("0")), street4BetSize(new QLineEdit("0")),
        street5BetSize(new QLineEdit("0"))
    { }
    

    And now your constructor doesn’t need to do any work.

    Now you can refer to street1BetSize and friends in the other member functions of MainWindow. However, it’s always very suspect when you have variables that are numbered, like streetXBetSize. This seems like a great place for an array or container. Why not try an std::vector<QLineEdit>, and then you can add and remove QLineEdits as you wish. Your class definition would now have:

    class MainWindow
    {
      // ...
     private:
      // ...
      std::vector<QLineEdit> streetBetSizes;
    }
    

    And your constructor could now simply do:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent), ui(new Ui::MainWindow)
    {
      for (int i = 0; i < 5; i++) {
        streetBetSizes.push_back(new QLineEdit("0"));
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm driving myself crazy trying to figure out how to implement tableView numberofRowsinSection and
I've been driving myself crazy trying to make this work. Variations of my attempt
I'm driving myself crazy trying to understand Expressions in LINQ. Any help is much
I've been driving myself crazy trying to get the Entity Framework to work as
I've been driving myself crazy trying to display thumbnail images for a list of
This is driving me crazy... With this simple code I keep getting file not
I've been driving myself crazy over the past few days over this one. We've
I'm using Flex 4. I'm driving myself crazy. Why won't the following work? //
I'm driving myself to despair trying to get an album added to a facebook
I am driving myself crazy over what I am sure is a basic error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.